There is an ongoing outage on the primary CPAN mirror. It is possible to work around the issue by using MetaCPAN as a mirror.

NAME

Crypt::URandom::MonkeyPatch - override core rand function to use system random sources

VERSION

version v0.1.2

SYNOPSIS

use Crypt::URandom::MonkeyPatch;

DESCRIPTION

This module globally overrides the builtin Perl function rand with one based on the operating system's cryptographic random number source, e.g. /dev/urandom.

The purpose of this module is monkey patch legacy code that uses rand for security purposes.

You can verify that it is working by running code with the CRYPT_URANDOM_MONKEYPATCH_DEBUG environment variable set, e.g.

local $ENV{CRYPT_URANDOM_MONKEYPATCH_DEBUG} = 1;

my $salt = random_string("........");

Every time the rand function is called, it will output a line such as

Crypt::URandom::MonkeyPatch::urandom used from Some::Package line 123

EXPORTS

rand

This globally overrides the builtin rand function using 31-bits of data from the operating system's random source.

KNOWN ISSUES

This module is not intended for use with new code, or for use in CPAN modules. If you are writing new code that needs a secure source of random bytes, then use Crypt::URandom or see the CPAN Author's Guide to Random Data for Security.

This should only be used when the affected code cannot be updated.

Because this updates the builtin function globally, it may affect other parts of your code.

SEE ALSO

Crypt::URandom

CORE

perlfunc

SOURCE

The development version is on github at "robrwo/perl-Crypt-URandom-MonkeyPatch" in github.com and may be cloned from "robrwo/perl-Crypt-URandom-MonkeyPatch.git" in github.com

SUPPORT

Only the latest version of this module will be supported.

Only Perl versions released in the past ten (10) years are supported, even though this module may run on earlier versions.

Please report any bugs or feature requests on the bugtracker website https://github.com/robrwo/perl-Crypt-URandom-MonkeyPatch/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

Reporting Security Vulnerabilities

Security issues should not be reported on the bugtracker website. Please see SECURITY.md for instructions how to report security vulnerabilities.

AUTHOR

Robert Rothenberg <rrwo@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2025 by Robert Rothenberg <rrwo@cpan.org>.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)