In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/d460397bbe36e991666185c0884015fdd0a30a6d?hp=f507d6f025503d42282fe562873d505fd9969d0d>
- Log ----------------------------------------------------------------- commit d460397bbe36e991666185c0884015fdd0a30a6d Author: Brian Phillips <[email protected]> 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 <[email protected]> ----------------------------------------------------------------------- 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
