summaryrefslogtreecommitdiff
path: root/pod/perlfunc.pod
diff options
context:
space:
mode:
authorChip Salzenberg <chip@perl.com>1997-02-20 07:04:03 +1200
committerChip Salzenberg <chip@atlantic.net>1997-02-22 02:41:53 +1200
commit93dc8474cb0353bd11e64192d213ed864602986f (patch)
tree5da5da58f19f1bc26e3c9e760237552b91a9b6e6 /pod/perlfunc.pod
parent7efcc441c96951d44f6ea2c8a2be6ddcc6ea6d4c (diff)
downloadperl-93dc8474cb0353bd11e64192d213ed864602986f.tar.gz
Automatically call srand() before rand() if user didn't
Diffstat (limited to 'pod/perlfunc.pod')
-rw-r--r--pod/perlfunc.pod32
1 files changed, 19 insertions, 13 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod
index 9d21587696..b3cf4e4205 100644
--- a/pod/perlfunc.pod
+++ b/pod/perlfunc.pod
@@ -2275,8 +2275,8 @@ If EXPR is omitted, uses $_.
Returns a random fractional number between 0 and the value of EXPR.
(EXPR should be positive.) If EXPR is omitted, returns a value between
-0 and 1. This function produces repeatable sequences unless srand()
-is invoked. See also srand().
+0 and 1. Automatically calls srand() unless srand() has already been
+called. See also srand().
(Note: if your rand function consistently returns numbers that are too
large or too small, then your version of Perl was probably compiled
@@ -3036,17 +3036,23 @@ root of $_.
=item srand EXPR
-Sets the random number seed for the C<rand> operator. If EXPR is omitted,
-uses a semi-random value based on the current time and process ID, among
-other things. In versions of Perl prior to 5.004 the default seed was
-just the current time(). This isn't a particularly good seed, so many
-old programs supply their own seed value (often C<time ^ $$> or C<time ^
-($$ + ($$ << 15))>), but that isn't necessary any more.
-
-You need something much more random than the default seed for
-cryptographic purposes, though. Checksumming the compressed output of
-one or more rapidly changing operating system status programs is the
-usual method. For example:
+=item srand
+
+Sets the random number seed for the C<rand> operator. If EXPR is
+omitted, uses a semi-random value based on the current time and process
+ID, among other things. In versions of Perl prior to 5.004 the default
+seed was just the current time(). This isn't a particularly good seed,
+so many old programs supply their own seed value (often C<time ^ $$> or
+C<time ^ ($$ + ($$ << 15))>), but that isn't necessary any more.
+
+In fact, it's usually not necessary to call srand() at all, because if
+it is not called explicitly, it is called implicitly at the first use of
+the C<rand> operator.
+
+However, you need something much more random than the default seed for
+cryptographic purposes. Checksumming the compressed output of one or
+more rapidly changing operating system status programs is the usual
+method. For example:
srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);