Thursday, June 09, 2011

/dev/urandom does not generate correct multi-byte sequences

If you use /dev/urandom with "tr" to generate random strings, you may have a problem if your shell uses a multi-byte locale. Upon encountering illegal bytes, tr will complain with "tr: Illegal byte sequence".

Setting the LC_TYPE=C before tr would do the trick:

cat /dev/urandom| LC_CTYPE=C tr -dc 'a-zA-Z0-9'

No comments: