@@ -6561,32 +6561,61 @@ X<rand> X<random>
6561
6561
6562
6562
=for Pod::Functions retrieve the next pseudorandom number
6563
6563
6564
- Returns a random fractional number greater than or equal to C<0> and less
6564
+ Returns a random fractional number greater than or equal to C<0> and B< less>
6565
6565
than the value of EXPR. (EXPR should be positive.) If EXPR is
6566
- omitted, the value C<1> is used. Currently EXPR with the value C<0> is
6567
- also special-cased as C<1> (this was undocumented before Perl 5.8.0
6568
- and is subject to change in future versions of Perl). Automatically calls
6569
- L<C<srand>|/srand EXPR> unless L<C<srand>|/srand EXPR> has already been
6570
- called. See also L<C<srand>|/srand EXPR>.
6566
+ omitted, the value C<1> is used.
6571
6567
6572
- Apply L<C<int>|/int EXPR> to the value returned by L<C< rand>|/rand EXPR>
6573
- if you want random integers instead of random fractional numbers. For
6574
- example,
6568
+ my $num1 = rand(); # Random float at least 0 and below 1
6569
+ my $num2 = rand(7); # Random float at least 0 and below 7
6570
+ my $num3 = int(rand(10)); # Random integer at least 0 and below 10
6575
6571
6576
- int(rand(10))
6572
+ B<Notes:>
6577
6573
6578
- returns a random integer between C<0> and C<9>, inclusive.
6574
+ =over
6575
+
6576
+ =item *
6577
+
6578
+ Calling C<rand> automatically calls L<C<srand>|/srand EXPR> unless
6579
+ srand has already been called.
6580
+
6581
+ =item *
6582
+
6583
+ Currently EXPR with the value C<0> is special-cased as C<1>. This was
6584
+ undocumented before Perl 5.8.0 and is subject to change in future versions of
6585
+ Perl.
6586
+
6587
+ =item *
6588
+
6589
+ As of Perl v5.20.0 C<rand()> uses the C<drand48> pseudorandom number generator
6590
+ to generate random numbers. As a PRNG C<drand48> should be sufficient for most
6591
+ non-cryptographic needs. If you need cryptographic random numbers check CPAN
6592
+ for crypto safe alternatives.
6593
+
6594
+ =back
6595
+
6596
+ =over
6579
6597
6580
- (Note: If your rand function consistently returns numbers that are too
6581
- large or too small, then your version of Perl was probably compiled
6582
- with the wrong number of RANDBITS.)
6598
+ =item B<Security:>
6583
6599
6584
6600
B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely
6585
6601
on it in security-sensitive situations.> As of this writing, a
6586
6602
number of third-party CPAN modules offer random number generators
6587
6603
intended by their authors to be cryptographically secure,
6588
- including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
6589
- and L<Math::TrulyRandom>.
6604
+ including:
6605
+
6606
+ =back
6607
+
6608
+ =over
6609
+
6610
+ =item * L<Data::Entropy>
6611
+
6612
+ =item * L<Crypt::Random>
6613
+
6614
+ =item * L<Math::Random::Secure>
6615
+
6616
+ =item * L<Math::TrulyRandom>
6617
+
6618
+ =back
6590
6619
6591
6620
=item read FILEHANDLE,SCALAR,LENGTH,OFFSET
6592
6621
X<read> X<file, read>
@@ -8951,11 +8980,8 @@ startup, and changing it during the program flow will not affect the
8951
8980
currently running process. See L<perlrun> for more details.
8952
8981
8953
8982
B<L<C<rand>|/rand EXPR> is not cryptographically secure. You should not rely
8954
- on it in security-sensitive situations.> As of this writing, a
8955
- number of third-party CPAN modules offer random number generators
8956
- intended by their authors to be cryptographically secure,
8957
- including: L<Data::Entropy>, L<Crypt::Random>, L<Math::Random::Secure>,
8958
- and L<Math::TrulyRandom>.
8983
+ on it in security-sensitive situations.> See documentation of C<rand> for
8984
+ a list of suitable alternatives.
8959
8985
8960
8986
=item stat FILEHANDLE
8961
8987
X<stat> X<file, status> X<ctime>
0 commit comments