in reply to Cryptographically Secure Psuedorandom Number Genergator - PRNG?
Math::Random::MT is a very well documented and tested PRNG with an extremely long periodicity. Unfortunately, the reference links within the modules POD are no longer valid, but google will find a zillion references including this one.
Of course, like any PRNG, it does generate a known sequence for a given seed, so the trick is to chose a seed at random. Time of day (in milliseconds), process number and various other things can be used, but they are at least to some extent inferable. A possibility would be to randomly pick a file from a directory and then a random offset within that file and then unpack 4 bytes at that location as a number and use that to seed MT.
#!perl -slw use strict; use Math::Random::MT qw[ rand srand ];; my @files = glob '*';; my $file = $files[ rand @files ]; open RND, '<', $file or die $!; my $slurp = do{ local $/; <RND> }; close RND; my $seed = unpack 'N', substr $slurp, rand( length $slurp - 4 ), 4; srand $seed; print rand for 1 .. 100;
With a suitable choice of directory that includes some binary images, especially if the contents of the directory change, the random choice of seed drawn this way should be pretty unpredictable. From then on, the sequence produced by MT is about as unpredicatable as PRNGs get.
|
|---|