NAME
Math::Random::Xoshiro256 - XS wrapper for xoshiro256** PRNG
SYNOPSIS
use Math::Random::Xoshiro256;
my $rng = Math::Random::Xoshiro256->new();
my $rand = $rng->rand64();
my $int = $rng->random_int(10, 20); # non-biased integer in [10, 20]
my $bytes = $rng->random_bytes(16); # 16 random bytes from PRNG
my $float = $rng->random_float(); # float in [0, 1] inclusive
my @arr = ('red', 'green', 'blue', 'yellow', 'purple');
my $rand_item = $rng->random_elem(@arr);
my @mixed = $rng->shuffle_array(@arr);
$rng->seed($seed) # Single 64bit seed
$rng->seed4(@seeds) # 4x 64bit seeds
DESCRIPTION
Implement the Xoshiro256** PRNG and expose so user friendly random methods.
This module is automatically seeded with entropy directly from your OS. On Linux this is /dev/urandom and on Windows it uses RtlGenRandom.
Alternately you can manually seed this if you need repeatable random numbers.
METHODS
- rand64()
-
Return an unsigned 64-bit random integer.
- random_int($min, $max)
-
Return a random integer (non-biased) in [$min, $max] inclusive.
- random_bytes($num)
-
Returns $num random bytes.
- random_float()
-
Returns a float in the interval [0, 1] inclusive.
- random_elem(@array)
-
Returns a single random element from the given array (returns undef if array is empty).
- shuffle_array(@array)
-
Returns a shuffled list using the Fisher-Yates algorithm with the PRNG instance. Input array is not modified.