Why the test of both $# and $1?
tr -dc '!-~' </dev/urandom | head -c ${1-12}; echo
Change to A-Za-z0-9, etc., to suit. tr -dc '!-~' </dev/urandom | head -c ${1-12}; echo
Change to A-Za-z0-9, etc., to suit.