diff options
author | Yves Orton <demerphq@gmail.com> | 2022-08-05 13:18:02 +0200 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2022-08-12 22:29:05 +0200 |
commit | bf2a3dae9f4f828fd1f2f8aaf4769f96520c9552 (patch) | |
tree | b58ad50f0d8d828bb5a890686e0ce7e82ae529ae /pod/perlfunc.pod | |
parent | 08da5deb5d0c842dab3fe5f4f5a450972a0eb67c (diff) | |
download | perl-bf2a3dae9f4f828fd1f2f8aaf4769f96520c9552.tar.gz |
Add a new env var PERL_RAND_SEED
This env var can be used to trigger a repeatable run of a script which
calls C<srand()> with no arguments, either explicitly or implicitly
via use of C<rand()> prior to calling srand(). This is implemented in
such a way that calling C<srand()> with no arguments in forks or
subthreads (again explicitly or implicitly) will receive their own seed
but the seeds they receive will be repeatable.
This is intended for debugging and perl development performance testing,
and for running the test suite consistently. It is documented that the
exact seeds used to initialize the random state are unspecified, and
that they may change between releases or even builds. The only guarantee
provided is that the same perl executable will produce the same results
twice all other things being equal. In practice and in core testing we
do expect consistency, but adding the tightest set of restrictions on
our commitments seemed sensible.
The env var is ignored when perl is run setuid or setgid similarly to
the C<PERL_INTERNAL_RAND_SEED> env var.
Diffstat (limited to 'pod/perlfunc.pod')
-rw-r--r-- | pod/perlfunc.pod | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 38ebb0d12d..fa16cbd69c 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -8480,7 +8480,7 @@ The point of the function is to "seed" the L<C<rand>|/rand EXPR> function so that L<C<rand>|/rand EXPR> can produce a different sequence each time you run your program. When called with a parameter, L<C<srand>|/srand EXPR> uses that for the seed; otherwise it -(semi-)randomly chooses a seed. In either case, starting with Perl 5.14, +(semi-)randomly chooses a seed (see below). In either case, starting with Perl 5.14, it returns the seed. To signal that your code will work I<only> on Perls of a recent vintage: @@ -8512,6 +8512,20 @@ combinations to test comprehensively in the time available to it each run. It can test a random subset each time, and should there be a failure, log the seed used for that run so that it can later be used to reproduce the same results. +If the C<PERL_RAND_SEED> environment variable is set to a non-negative +integer during process startup then calls to C<srand()> with no +arguments will initialize the perl random number generator with a +consistent seed each time it is called, whether called explicitly with +no arguments or implicitly via use of C<rand()>. The exact seeding that +a given C<PERL_RAND_SEED> will produce is deliberately unspecified, but +using different values for C<PERL_RAND_SEED> should produce different +results. This is intended for debugging and performance analysis and is +only guaranteed to produce consistent results between invocations of the +same perl executable running the same code when all other factors are +equal. The environment variable is read only once during process +startup, and changing it during the program flow will not affect the +currently running process. See L<perlrun> for more details. + B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely on it in security-sensitive situations.> As of this writing, a number of third-party CPAN modules offer random number generators |