Unix::OpenBSD::Random - interface to arc4random(3) on OpenBSD
use Unix::OpenBSD::Random qw(arc4random arc4random_uniform); my $x = arc4random(); my $y = arc4random(2); # coinflip
This module is a wafer-thin wraper around the arc4random(3) library function on OpenBSD. Other OS have this function call though may require arc4random_stir(3) or such calls that this module does not support.
Returns an integer in the uint32_t range.
uint32_t
Returns a string filled with the given number of bytes of random data. This string may contain non-printable or even NUL characters so might best be converted to some other form before being displayed or used where such characters may cause problems.
NUL
my $buf = arc4random_buf(8); printf "%vx\n", $buf; my $string = unpack "H*", $buf;
Will throw an exception if the length is outside the range of a size_t.
size_t
Note that this interface has been made more Perl-like than the C version arc4random_buf(buf, nbytes).
arc4random_buf(buf, nbytes)
Returns an integer no more than the upper_bound. Avoids modulo bias. Will throw an exception if upper_bound is outside the range of allowed values for uint32_t.
Please report any bugs or feature requests to bug-unix-openbsd-random at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Unix-OpenBSD-Random.
bug-unix-openbsd-random at rt.cpan.org
Patches might best be applied towards:
https://github.com/thrig/Unix-OpenBSD-Random
The newly being written thing and lack of testing on 32-bit systems. Lack of XS skill on the part of the author.
arc4random_uniform accepts 0 as an upper bound (and arc4random_buf a length of 0). If this is a problem add a check before calling into this module.
arc4random_uniform
0
arc4random_buf
https://man.openbsd.org/arc4random.3
https://www.openbsd.org/papers/eurobsdcon2014_arc4random/mgp00001.html
thrig - Jeremy Mates (cpan:JMATES) <jmates at cpan.org>
<jmates at cpan.org>
Copyright (C) 2018 by Jeremy Mates
This program is distributed under the (Revised) BSD License: http://www.opensource.org/licenses/BSD-3-Clause
To install Unix::OpenBSD::Random, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Unix::OpenBSD::Random
CPAN shell
perl -MCPAN -e shell install Unix::OpenBSD::Random
For more information on module installation, please visit the detailed CPAN module installation guide.