Random Password Generator

I found this script on the web somewhere quite a while back. Kudos to the author and if I ever find it again I'll be sure to link to the original.

#!/usr/bin/env bash
 
PWDLEN=$1
 
if [[ -z $PWDLEN ]] ; then
    PWDLEN=12
fi
 
char=(
 a b c d e f g h i j k l m n o p q r s t u v w x y z 
 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 
 0 1 2 3 4 5 6 7 8 9 ! @ \# $ % ^ \&
)
 
max=${#char[*]}
 
for i in $(seq 1 $PWDLEN)
do
    let rand=${RANDOM}%${max}
    str="${str}${char[$rand]}"
done
echo $str

Use like this: (numeric value determines password length)

$ ./pwdgen.sh
ctoxF@koU8vl

$ ./pwdgen.sh 32
Z8338T4o5QPTC4HLcZZoB2vmFKMIwIFe
Burtronix Banner W3C Banner