+ # /dev/urandom isn't guaranteed to generate valid multi-byte characters.
+ # Specifying the C locale eliminates the "Illegal byte sequence" error
+ # that 'tr' outputs in such cases.
+ LC_CTYPE=C tr -cd "$CHAR" < /dev/urandom 2>/dev/null | head -c "$len" 2>/dev/null