summaryrefslogtreecommitdiff
path: root/pod
diff options
context:
space:
mode:
authorBrian Phillips <bphillips@cpan.org>2010-06-30 10:31:25 -0500
committerDavid Golden <dagolden@cpan.org>2010-07-01 06:50:31 -0400
commitd460397bbe36e991666185c0884015fdd0a30a6d (patch)
treef1ffe5e2a9ea5034580689cadd4f182a8ff04da4 /pod
parentf507d6f025503d42282fe562873d505fd9969d0d (diff)
downloadperl-d460397bbe36e991666185c0884015fdd0a30a6d.tar.gz
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 <bphillips@cpan.org>
Diffstat (limited to 'pod')
-rw-r--r--pod/perlfunc.pod8
1 files changed, 5 insertions, 3 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 43a334de3f..c86af43d86 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.