NAME

Random::Simple - Generate good random numbers in a user consumable way.

SYNOPSIS

use Random::Simple;

my $prng           = new Random::Simple();

my $coin_flip      = random_int(1, 2);
my $die_roll       = random_int(1, 6);
my $random_percent = random_float() * 100;
my $buffer         = random_bytes(8);

my @arr            = ('red', 'green', 'blue');
my $rand_item      = random_elem(@arr);
my @mixed          = shuffle_array(@arr);

DESCRIPTION

Perl's internal rand() function uses drand48 which is an older pseudorandom number generator and may have limitations. Random::Simple uses PCG which is: modern, simple, well vetted, and fast. Using Random::Simple will automatically upgrade/override the core rand() function to use a better PRNG.

Random::Simple is automatically seeded with entropy directly from your OS. On Linux this is /dev/urandom and on Windows it uses RtlGenRandom.

When you use Random::Simple we automatically upgrade rand() and srand() to use a modern PRNG with better statistical properties. As a bonus you also get a handful of other useful random related methods.

METHODS

CAVEATS

PCG uses two 64bit unsigned integers for seeding. High quality seeds are needed to generate good random numbers. Random::Simple automatically generates high quality seeds by reading random bytes from your operating system and converting appropriately.

If you manually seed Random::Simple, make sure you use good seeds that are mostly non-zero. The larger the number the better seed it will make. A good seed is a decimal number with 18 or 19 digits.

BUGS

Submit issues on Github: https://github.com/scottchiefbaker/perl-Random-Simple/issues

SEE ALSO

AUTHOR

Scott Baker - https://www.perturb.org/