Generate a random string of given length.

This is a quick one liner to generate a random string of length X on the linux command line. Useful for testing purposes where you need random strings, or to generate passwords on the fly.

# generate a random alphanumeric string of length X
tr -cd 0-9a-zA-Z < /dev/urandom | head -c $X

# example with length 32
tr -cd 0-9a-zA-Z < /dev/urandom | head -c 32
# kUeqXGIrEfOyBdVmjKMhH2ppAxaXLS2r