Crypt::URandom(3)
β¨ Crypt::URandom β¨
okay bestie, so this is the Crypt::URandom(3) page β yes that's the perldoc section 3 situation β and it's literally all about Crypt::URandom - Provide non blocking randomness. no cap, that's the whole name. π
π VERSION π
So this doc is describing Crypt::URandom version 0.55. that's it, that's the version. periodt.
π¦ SYNOPSIS π¦
okay so there's two ways to do this and both are valid, pick your fighter:
use Crypt::URandom();
my $random_string_50_bytes_long = Crypt::URandom::urandom(50);
OR β and this is the one where you import the function directly, main character energy:
use Crypt::URandom qw( urandom );
my $random_string_50_bytes_long = urandom(50);
πΈ DESCRIPTION πΈ
So the whole point of this module, bestie, is that it gives you an interface to the strongest available source of non-blocking randomness on whatever platform you're on right now. iconic behaviour honestly.
The platforms it supports currently: anything that supports getrandom(2), anything with /dev/urandom, and versions of Windows greater than or equal to Windows 2000. that's the roster. π«Ά
β SUBROUTINES/METHODS β
π urandom
This one takes an integer and hands you back a string of the same size filled with random data. slay.
It will throw an exception if the requested amount of random data is not returned β so like, it's not gonna silently give you less and let you live a lie. π«‘
The first call will initialize the native cryptographic libraries (if necessary) and load all the required Perl libraries.
And heads up: this call is a buffered read on non Win32 platforms that do not support getrandom(2) or equivalent. iykyk.
π
urandom_ub
Same deal, different vibe: accepts an integer, returns a string of the same size filled with random data. throws an exception if the requested amount of random data is not returned.
First call initializes the native cryptographic libraries (if necessary) and loads all the required Perl libraries.
The difference? This call is an unbuffered sysread on non Win32 platforms that do not support getrandom(2) or equivalent. the _ub is giving unbuffered, she said what she said. π
π₯ getrandom
This function accepts an integer and returns a string of the same size filled with random data on platforms that implement getrandom(2). throws an exception if the requested amount of random data is not returned.
okay real talk β οΈ β this is NOT portable across all operating systems. it's just made available if you need high-speed generation of random numbers. don't come crying to her when it doesn't work on your weird platform, she warned you.
And like, a very specific little quirk: if an integer is not supplied as an argument, this function will return an empty string as a result β which is the same thing that happens as if the integer 0 is supplied as an argument. so nothing and zero are wearing the same outfit. π
π DIAGNOSTICS π
Okay so here's every way this module can yell at you, and what she means by it:
No secure alternative for random number generation for Win32 versions older than W2Kβ the module cannot run on versions of Windows earlier than Windows 2000, because there are no cryptographic functions provided by the operating system. sorry babe.Could not import CryptAcquireContextβ the module was unable to load theCryptAcquireContextAfunction from theadvapi32dynamic library. Theadvapi32library cannot probably be loaded.CryptAcquireContext failedβ the module was unable to call theCryptAcquireContextAfunction from theadvapi32dynamic library.Could not import CryptGenRandomβ the module was unable to load theCryptGenRandomfunction from theadvapi32dynamic library.Could not import SystemFunction036β the module was unable to load theSystemFunction036function from theadvapi32dynamic library.The length argument must be supplied and must be an integerβ the get method must be called with an integer argument to describe how many random bytes are required. it needs to know the count, bestie. π’CryptGenRandom failedβ the Windows 2000CryptGenRandommethod call failed to generate the required amount of randomness.RtlGenRand failedβ the post Windows 2000RtlGenRandmethod call failed to generate the required amount of randomness.Only read n bytes from pathβ the/dev/urandomdevice did not return the desired amount of random bytes.Failed to read from pathβ the/dev/urandomdevice returned an error when being read from.Failed to open pathβ the/dev/urandomdevice returned an error when being opened.
π CONFIGURATION AND ENVIRONMENT π
Good news: Crypt::URandom requires no configuration files or environment variables. zero setup, we love a low-maintenance icon. π§
BUT β one tiny exception, and it's a build-time thing: if the environment variableCRYPT_URANDOM_BUILD_DEBUGis specified when runningperl Makefile.PLormake testANDgetrandom(2)or its equivalents cannot be detected, extra debug will be shown to show the failures to detect these functions. so it's like a little detective mode for the build. π
π DEPENDENCIES π
- If the platform is Win32, the
Win32::APImodule will be required. - Otherwise, no other modules other than those provided by perl will be required. so like, core and clean. β¨
π INCOMPATIBILITIES π
None reported. she's not aware of any beef. ποΈ
π BUGS AND LIMITATIONS π
To report a bug, or view the current list of bugs, please visit:
https://github.com/david-dick/crypt-urandom/issues
that's the spot. go tell her what's wrong, she'll listen. π«Ά
π AUTHOR π
David Dick "<ddick@cpan.org>" β put some respect on the name.
π ACKNOWLEDGEMENTS π
The Win32::API code for interacting with Microsoft's CryptoAPI https://en.wikipedia.org/wiki/Microsoft_CryptoAPI was copied with extreme gratitude from Crypt::Random::Source::Strong::Win32 by Max Kanat-Alexander https://metacpan.org/author/MKANAT. credit where credit is due, always. π«‘π
π LICENSE AND COPYRIGHT π
Copyright (c) 2025, David Dick "<ddick@cpan.org>". All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. so go off, remix it. π
π¨ DISCLAIMER OF WARRANTY π¨
okay so this part is in ALL CAPS in the original and we are absolutely keeping it that way because it is legally screaming at you. read it, bestie, it matters:
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
and that's the whole page, babe! π little sign-off from the footer so nothing gets lost: this all comes from perl v5.42.0, dated 2026-03-23, and the page is Crypt::URandom(3). πβ¨ now go generate some genuinely unpredictable bytes, mwah π«Άπ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Crypt-URandom 0.550.0-160000.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Crypt-URandom 0.550.0-160000.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Crypt-URandom 0.550.0-160000.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Crypt-URandom 0.550.0-160000.1.1 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms