Search code examples
bashmacosrandommacos-monterey

Has anything changed with /dev/urandom on MacOS Monterey?


I used to be able to generate a random character sequence from /dev/urandom using the following line:

cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9-_!@#$%^&*()_+{}|:<>?=' | fold -w 100 | head -n 1 | grep -i '[!@#$%^&*()_+{}|:<>?=]' | tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]'

but this no longer functions after I upgraded to Monterey. The output I receive is nothing more than Input error. Has something changed with this OS version? How can I now generate a sequence of 100 random characters from /dev/urandom?


Solution

  • In Monterey, locale shows LANG as set, and the grand override value, LC_ALL as unset, as it is typically set elsewhere for example https://docs.oracle.com/cd/E19455-01/806-0169/utf8-98/index.html To make this work in Monterey, just change the language or the override to the POSIX standard default:

    LANG=C or LC_ALL=C

    In Monterey, the character type locale could be set to: LC_CTYPE=en.US.UTF-8 to avoid angle-bracket-enclosed escape codes which sneak through given that LANG is set now.