Interview Prep/Shell Scripting/Variables, quoting and expansions

What does `$RANDOM` give you, and is it suitable for passwords or tokens?

IntermediateConceptVariables, quoting and expansions
Answer

$RANDOM returns a pseudo-random integer from 0 to 32767. It is fine for jitter (sleep $((RANDOM % 30)) to spread cron load) but not for secrets: the range is tiny and it is predictable. For secrets use the kernel CSPRNG:

openssl rand -base64 32
head -c 32 /dev/urandom | base64
echo "$SRANDOM"   # Bash 5.1+: 32-bit value from the system CSPRNG
All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Variables, quoting and expansions