develooper Front page | perl.perl5.changes | Postings from July 2010

[perl.git] branch blead, updated. v5.13.2-132-gd460397

David Golden
July 1, 2010 03:54
[perl.git] branch blead, updated. v5.13.2-132-gd460397
Message ID:
In perl.git, the branch blead has been updated


- Log -----------------------------------------------------------------
commit d460397bbe36e991666185c0884015fdd0a30a6d
Author: Brian Phillips <>
Date:   Wed Jun 30 10:31:25 2010 -0500

    Add additional notes regarding srand and forking
    perldoc -f srand states that typical use requires no srand() to be
    called.  This is true with the exception of forking where you may not
    want the same seed across various child processes (i.e. mod_perl).
    This patch simply adds a note reminding the reader of this fact and
    more specifically states that srand should only be called once per
    *process* (instead of the previous language of once per *script*).
    Signed-off-by: Brian Phillips <>

Summary of changes:
 pod/perlfunc.pod |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 43a334d..c86af43 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -6172,15 +6172,17 @@ Most programs won't even call srand() at all, except those that
 need a cryptographically-strong starting point rather than the
 generally acceptable default, which is based on time of day,
 process ID, and memory allocation, or the F</dev/urandom> device
-if available.
+if available. You may also want to call srand() after a fork() to
+avoid child processes sharing the same seed value as the parent (and
+consequently each other).
 You can call srand($seed) with the same $seed to reproduce the
 I<same> sequence from rand(), but this is usually reserved for
 generating predictable results for testing or debugging.
 Otherwise, don't call srand() more than once in your program.
-Do B<not> call srand() (i.e., without an argument) more than once in
-a script.  The internal state of the random number generator should
+Do B<not> call srand() (i.e., without an argument) more than once per
+process.  The internal state of the random number generator should
 contain more entropy than can be provided by any seed, so calling
 srand() again actually I<loses> randomness.

Perl5 Master Repository Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About