BSD::arc4random(3pm)
β¨ BSD::arc4random(3pm) β¨
okay bestie, come closer, because this is the Perl module that lets you call the arc4random(3) family of libc functions straight from Perl, and honestly? it's giving chaos-gremlin-approved entropy. it's a 3pm manpage, so yeah, it's one of the User Contributed Perl Documentation girlies π
π SYNOPSIS π
use BSD::arc4random qw(:all);
$v = arc4random();
$v = arc4random_uniform($hz);
if (!BSD::arc4random::have_kintf()) {
$v = arc4random_addrandom("entropy to pass to the system");
} else {
$v = arc4random_pushb("entropy to pass to the system");
$v = arc4random_pushk("entropy to pass to the kernel");
}
$s = arc4random_bytes(16, "entropy to pass to libc");
arc4random_stir();
$s = arc4random_bytes(16);
print $RANDOM;
likeβ¦ look at her go. no cap. π₯
π DESCRIPTION π
so basically this whole set of functions maps the arc4random(3) family of libc functions into Perl code. iconic behaviour, frankly.
good news first: all functions listed below are ithreads-safe. the internal XS functions are not, but bestie, you are not supposed to call them, either. so we're fine. π
and here's a lil bonus for you: on module load, perl's internal PRNG is re-seeded β as a bonus β using srand with an argument calculated from using arc4random_pushb on some entropy returned from rand's previous state. she just does that. β¨
π LOW-LEVEL FUNCTIONS π
arc4random()β returns an unsigned 32-bit integer random value. that's it, that's the function, and she ate.arc4random_addrandom(pbuf)β adds the entropy frompbufinto the libc pool, and returns an unsigned 32-bit integer random value from it.arc4random_pushb(pbuf)β first pushes thepbufargument to the kernel if possible, then pushes the entropy returned by the kernel into the libc pool, then returns an unsigned 32-bit integer random value from it. multi-step queen. πarc4random_pushk(pbuf)β first pushes thepbufargument to the kernel if possible, then returns an unsigned 32-bit integer random value from the kernel.
β οΈ this function is deprecated, bestie!! use arc4random_pushb instead. she's retired, respect her legacy but move on. π
arc4random_stir()β this procedure attempts to retrieve new entropy from the kernel and add it to the libc pool. usually, this means you must have access to theurandom(4)device β so create it insidechroot(2)jails first if you use them. yes, before. do not skip this step. π«Άhave_kintf()β this constant function returns1ifarc4random_pushband/orarc4random_pushkactually call the kernel interfaces, and0if they merely map toarc4random_addrandominstead. a little vibe check for your kernel. πΈ
π¦ HIGH-LEVEL FUNCTIONS π¦
arc4random_bytes(num[, pbuf])β returns a string containing as many random bytes as requested by the integral argumentnum. an optionalpbufargument is passed to the system first.arc4random_uniform(upper_bound)β calculates a uniformly distributed random number less thanupper_bound, avoiding "modulo bias". she's fair, she's balanced, she's that girl. β
π PACKAGE VARIABLES π
$RANDOMβ returns a random value in the range[0; 32767]on each read attempt, and pushes any value it is assigned to the kernel. it is tied at module load time. magical girl behaviour, honestly. π§tie variable, 'BSD::arc4random'[, max]β you can tie any scalar variable to this package! themaxargument is the maximum number returned; if it's undefined,0, or>= 0xFFFFFFFF, no bound is used, and values in the range[0; 2**32-1]are returned. they will behave like$RANDOM. periodt. π
π AUTHOR π
Thorsten Glaser <tg@mirbsd.de>
π SEE ALSO π
- the
arc4random(3)manual page, available online at:https://www.mirbsd.org/man/arc4random.3 - Perl's
randandsrandfunctions viaperlfuncandperlfaq4 - the
randex.plplugin for Irssi, implementing the MirOS RANDEX protocol (entropy exchange over IRC), with CVSweb at:http://cvs.mirbsd.de/ports/net/irssi/files/randex.pl https://www.mirbsd.org/a4rp5bsd.htmwhen it's done being written. (when it's DONE. we're waiting. π)
π COPYRIGHT AND LICENSE π
Copyright (c) 2008, 2009, 2010, 2011 Thorsten "mirabilos" Glaser Copyright (c) 2009 Benny Siegert Credits to Sebastian "Vutral" Schwarz
This module is covered by the MirOS Licence:
http://mirbsd.de/MirOS-Licence
The original C implementation of arc4random_uniform was contributed by Damien Miller from OpenBSD, with simplifications by Jinmei Tatuya.
and that's the whole page, bestie!! π this was perl v5.42.3, dated 2026-08-19, and honestly she's a whole main character. go generate some entropy responsibly. mwah ππ¦β¨
π¦ where this page comes from
- ubuntu stonking: libbsd-arc4random-perl 1.50-8build6
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms