Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

srand

Seeds the pseudo-random number generator used by rand.

Sets the seed for the random number generator used by rand. If EXPR is provided and defined, its integer value is used. Otherwise, a system-derived seed (nanosecond timestamp XOR PID) is used. Creates a new StdRng instance via seed_from_u64. Returns the seed that was actually used as an integer.

Synopsis

srand(42);             # deterministic sequence
srand;                 # seed from system entropy
my $seed = srand;      # returns the seed used

See Also

rand