Crypt::Random - Cryptographically Secure, True Random Number Generator.
$Revision: 1.11 $
$Date: 2001/07/12 15:59:47 $
use Crypt::Random qw( makerandom );
my $r = makerandom ( Size => 512, Strength => 1 );
Crypt::Random is an interface module to the /dev/random device found on most modern unix systems. It also interfaces with egd, a user space entropy gathering daemon, available for systems where /dev/random (or similar) devices are not available. When Math::Pari is installed, Crypt::Random can generate random integers of arbitrary size of a given bitsize or in a specified interval.
The /dev/random driver maintains an estimate of true randomness in the pool and decreases it every time random strings are requested for use. When the estimate goes down to zero, the routine blocks and waits for the occurrence of non-deterministic events to refresh the pool.
When the routine is blocked, Crypt::Random's read() will be blocked till desired amount of random bytes have been read off of the device. The /dev/random kernel module also provides another interface, /dev/urandom, that does not wait for the entropy-pool to recharge and returns as many bytes as requested. For applications that must not block (for a potentially long time) should use /dev/urandom. /dev/random should be reserved for instances where very high quality randomness is desired.
If there's a hardware random number generator available, for instance the Intel i8x0 random number generator, please use it instead of /dev/random!. It'll be high quality, a lot faster and it won't block! Usually your OS will provide access to the RNG as a device, eg (/dev/intel_rng).
Generates a random number of requested bitsize in base 10. Following arguments can be specified.
Bitsize of the random number.
Value of 1 implies that /dev/random should be used for requesting random bits while 0 implies /dev/urandom.
Alternate device to request random bits from.
Value of 0 (default) implies that the high bit of the generated random number is always set, ensuring the bitsize of the generated random will be exactly Size bits. For uniformly distributed random numbers, Uniform should be set to 1.
Generates a random number in the specified interval. In addition to the arguments to makerandom() following attributes can be specified.
Inclusive Lower limit.
Exclusive Upper limit.
Generates a random octet string of specified length. In addition to Strength, Device and Verbosity, following arguments can be specified.
Length of the desired octet string.
An octet string consisting of characters to be skipped while reading from the random device.
Crypt::Random needs Math::Pari 2.001802 or higher.
Vipul Ved Prakash, <firstname.lastname@example.org>
To install Crypt::Random, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.