in reply to random question
Anyway, here's a simple one that returns numbers in the range 0..65535:
use Digest::SHA 'sha384_hex'; my $rng = generate_rng('salty' . localtime() . $$); print $rng->(), "\n" for 0..100; sub generate_rng { my $seed = shift; return sub { $seed = sha384_hex($seed); my $rnd = hex(substr($seed, 0, 4)); return $rnd; }; }
For further study, you might want to look at OpenBSD's rand() which is about as simple as it gets. (It's also a poor one; its use is discouraged.)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: random question
by Anonymous Monk on Sep 09, 2013 at 18:48 UTC |