NAME

Unix::OpenBSD::Random - interface to arc4random(3) on OpenBSD

SYNOPSIS

use Unix::OpenBSD::Random qw(arc4random arc4random_uniform);

my $x = arc4random();
my $y = arc4random(2);    # coinflip

DESCRIPTION

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.

FUNCTIONS

arc4random

Returns an integer in the uint32_t range.

arc4random_buf length

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.

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.

Note that this interface has been made more Perl-like than the C version arc4random_buf(buf, nbytes).

arc4random_uniform upper_bound

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.

BUGS

Reporting Bugs

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.

Patches might best be applied towards:

https://github.com/thrig/Unix-OpenBSD-Random

Known Issues

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.

SEE ALSO

https://man.openbsd.org/arc4random.3

https://www.openbsd.org/papers/eurobsdcon2014_arc4random/mgp00001.html

AUTHOR

thrig - Jeremy Mates (cpan:JMATES) <jmates at cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2018 by Jeremy Mates

This program is distributed under the (Revised) BSD License: http://www.opensource.org/licenses/BSD-3-Clause