develooper Front page | perl.perl5.changes | Postings from August 2022

[Perl/perl5] 42f55d: Add a new env var PERL_RAND_SEED

Yves Orton via perl5-changes
August 6, 2022 21:06
[Perl/perl5] 42f55d: Add a new env var PERL_RAND_SEED
Message ID:
  Branch: refs/heads/yves/consistent_srand
  Commit: 42f55d4ee664f1ebaf90d57980f8c786af6567bc
  Author: Yves Orton <>
  Date:   2022-08-06 (Sat, 06 Aug 2022)

  Changed paths:
    M dist/threads/t/thread.t
    M dist/threads/t/version.t
    M dist/threads/threads.xs
    M embedvar.h
    M handy.h
    M hv.c
    M intrpvar.h
    M perl.c
    M perl.h
    M pod/perldelta.pod
    M pod/perlfunc.pod
    M pod/perlrun.pod
    M pp.c
    M pp_sys.c
    M sv.c
    M t/op/srand.t
    A t/run/runenv_randseed.t

  Log Message:
  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 use
seemed sensible.

The env var is ignored when perl is run setuid or setgid similarly to
the C<PERL_INTERNAL_RAND_SEED> env var. Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About