Perl6: Random numbers and bytes emulating arc4random
Switch branches/tags
Nothing to show
Failed to load latest commit information.
lib/Crypt Improve Windows error handling May 21, 2016
t Improve tests Apr 30, 2016
.gitignore Notable cleanup, especially docs May 11, 2016
.travis.yml Add Travis Apr 10, 2016
META6.json Notable cleanup, especially docs May 11, 2016


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.