Crypt::Random(3)
π Crypt::Random(3) β Cryptographically Secure, True Random Number Generator π
okay bestie, welcome to the User Contributed Perl Documentation page for Crypt::Random(3) β manual name folded in, vibes fully immaculate. π
πΈ NAME πΈ
Crypt::Random β Cryptographically Secure, True Random Number Generator.
β¨ SYNOPSIS β¨
use Crypt::Random qw( makerandom );
my $r = makerandom ( Size => 512, Strength => 1 );
π¦ DESCRIPTION π¦
Crypt::Random is an interface module to the /dev/random and /dev/urandom device found on most modern unix systems. It also interfaces with egd, a user space entropy gathering daemon, available for systems where /dev/random (or similar) devices are not available. When Math::Pari is installed, Crypt::Random can generate random integers of arbitrary size of a given bitsize or in a specified interval.
π ALTERNATIVES π
Crypt::Random has numerous options for obtaining randomness. If youβd prefer a simpler module that provides cryptographic grade randomness, Crypt::URandom should be considered.
The CPANSec group has developed the CPAN Author's Guide to Random Data for Security https://security.metacpan.org/docs/guides/random-data-for-security.html that should be reviewed before dealing with randomness.
π BLOCKING BEHAVIOUR π
Since kernel version 5.6 in 2020, /dev/random is no longer blocking and there is effectively no difference between /dev/random and /dev/urandom. Indeed there has been no difference in the quality of randomness from either in many years. /dev/random now only blocks on startup of the system and only for a very short time.
π₯ HARDWARE RNG π₯
If there's a hardware random number generator available, for instance the Intel i8x0 random number generator, you can use it instead of /dev/random or /dev/urandom. Usually your OS will provide access to the RNG as a device, eg (/dev/intel_rng).
π METHODS π
π makerandom() π
Generates a random number of requested bitsize in base 10. Following arguments can be specified.
Sizeβ Bitsize of the random number.Providerβ Specifies the name of the Provider to be used. Specifying a Provider overrides Strength.
Options are:
devrandomβ Uses/dev/randomto generate randomness.devurandomβ Uses/dev/urandomto generate randomness.Win32APIβ Uses the Windows APISystemFunction036(RtlGenRandom) to generate randomness on Windows Operating Systems.egd (INSECURE)β An Entropy Gathering Daemon (egd) daemon is read to obtain randomness. As egd has not been updated since 2002 it has been moved to the low strength provider list.randβ Generates randomness based on Perl'sCrypt::URandomurandom function.
Strength 0 || 1β Value of1implies that/dev/randomor/dev/urandomshould be used for requesting random bits while0implies insecure includingrand.
As of release 1.55 Strength defaults to 1 (/dev/random or /dev/urandom or rand (using Crypt::URandom::urandom)).
Deviceβ Alternate device to request random bits from.Uniform 0 || 1β Value of0(default) implies that the high bit of the generated random number is always set, ensuring the bitsize of the generated random will be exactlySizebits. For uniformly distributed random numbers,Uniformshould be set to1.
π§ makerandom_itv() π§
Generates a random number in the specified interval. In addition to the arguments to makerandom() following attributes can be specified.
Lowerβ Inclusive Lower limit.Upperβ Exclusive Upper limit.
π makerandom_octet() π
Generates a random octet string of specified length. In addition to Strength, Device and Verbosity, following arguments can be specified.
Lengthβ Length of the desired octet string.Skipβ An octet string consisting of characters to be skipped while reading from the random device.
π DEPENDENCIES π
Crypt::Random needs Math::Pari 2.001802 or higher.
π«Ά SEE ALSO π«Ά
Crypt::URandom should be considered as simpler module for obtaining cryptographically secure source of Randomness.
The CPANSec group has developed the CPAN Author's Guide to Random Data for Security https://security.metacpan.org/docs/guides/random-data-for-security.html that should be reviewed before dealing with randomness.
β BIBLIOGRAPHY β
random.cby Theodore Ts'o. Found indrivers/chardirectory of the Linux kernel sources.Handbook of Applied Cryptographyby Menezes, Paul C. van Oorschot and Scott Vanstone.
π LICENSE π
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
πΈ AUTHOR πΈ
Vipul Ved Prakash, <mail@vipul.net>
π Thatβs the whole Crypt::Random(3) page, bestie β brought to you by perl v5.42.2, dated 2025-11-20. π
π¦ where this page comes from
- alpine 3.24: perl-crypt-random-doc 1.57-r0 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms