variable

Bash SRANDOM — 32-bit random integer

Each expansion returns a pseudorandom integer in the unsigned 32-bit range; assigning a value does not seed it. Available on the tested Bash 5.2 baseline, not guaranteed in older releases. Do not rely on it as a credential generator. Run in a fresh private directory with HOME set to that directory and LC_ALL=C. Expected output (one item per line): in range.

Formal Syntax & Structure

bash syntaxbash
${SRANDOM}

Return Value

integer

An unsigned 32-bit random integer on the tested implementation.

Working Example

Example Snippetbash
n=$SRANDOM[[ $n =~ ^[0-9]+$ ]] || exit 1(( n >= 0 && n <= 4294967295 )) || exit 1printf 'in range\n'
Bash Reference