Perl6: Random numbers and bytes emulating arc4random
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
t Improve tests Apr 30, 2016
.travis.yml Add Travis Apr 10, 2016
META6.json Minor version bump for META6.json Apr 26, 2017


Build Status Build status

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);

Entropy Sources

Random bytes are drawn from /dev/urandom on Unix-like systems, and CryptGenRandom() on Windows.

Copyright & License

Copyright 2016 Shawn Kinkade.

This module may be used under the terms of the Artistic License 2.0.