Random numbers and bytes mimicking arc4random()
.
use Crypt::Random;
# Random positive Int, defaulting to 32-bit
my Int $foo = crypt_random();
my Int $foo64 = crypt_random(Int(64/8));
# Random Int between 0 and $upper_bound (exclusive)
my Int $bar = crypt_random_uniform($upper_bound);
my Int $bar128 = crypt_random_uniform($upper_bound, Int(128/8));
# Buf of $len random bytes
my Buf $baz = crypt_random_buf($len);
Additional useful functions built upon the above primitives.
use Crypt::Random::Extra;
my Str $uuid = crypt_random_UUIDv4();
my Int $prime = crypt_random_prime()
my Int $prime2048 = crypt_random_prime(Int(2048/8));
# Random sampling of $set, which can be a Blob or List
my Array @sample = crypt_random_sample($set, $count);
Random bytes are drawn from /dev/urandom
on Unix-like systems, and
CryptGenRandom()
on Windows.
Copyright 2016 Shawn Kinkade.
This module may be used under the terms of the Artistic License 2.0.