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
More on Variables, quoting and expansions
What are the rules for assigning variables in Bash?BeginnerWhat is the difference between single quotes, double quotes and `$'...'`?BeginnerWhy should you almost always quote variable expansions? Show what goes wrong.BeginnerExplain the difference between `"$@"`, `"$*"`, `$@` and `$*`.IntermediateWhat do `${var:-default}`, `${var:=default}`, `${var:+alt}` and `${var:?msg}` do?IntermediateHow do you strip prefixes and suffixes with parameter expansion?Intermediate