TrulyRandom - Generate non-pseudo random numbers in pure Perl
use Math::TrulyRandom; $random = truly_random_value();
The TrulyRandom module provides an ability to generate truly random numbers from within Perl programs. The source of the randomness is from interrupt timing discrepancies.
$random = truly_random_value();
This code uses only CORE Perl code, but needs Time::HiRes::ualarm which is not supported on Win32.
The name is a bit misleading, as this technique generates decent entropy only on select platforms.
This implementation is based on version 1 of TrueRand, which had numerous issues and was superseded by TrueRand 2.1. The expected entropy for each 32-bit value of this code is approximately 8-16 bits, and the mixing method leaves much to be desired. The newer version uses cryptographic hashes for mixing, as well as mixing the result of multiple raw calls to create one result. The documentation specifically warns to not use the raw call (hence this earlier version does exactly what the author now indicates not to do).
More sophisticated systems like HAVEGE (http://www.issihosts.com/haveged/) generate randomness with more sources and run much faster. These are meant to feed entropy pools, which are in turn managed and doled out via /dev/random. This module is userspace "voodoo entropy" and really shouldn't be used.
The random numbers take a long time (in computer terms) to generate, so are only really useful for seeding pseudo random sequence generators. There are other solutions that can generate entropy from timer/scheduler jitter that run faster and use less CPU (e.g. Crypt::Random::TESHA2).
This implementation derives from the truly random number generator function developed by Matt Blaze and Don Mitchell, and is copyright of AT&T.
Other parts of this perl extension are copyright of Systemics Ltd (http://www.systemics.com/).
The rewrite in pure Perl is Copyright (c) 2013, Dana Jacobsen.