2.8. Generating Different Random NumbersProblemEvery time you run your program you get the same set of "random" numbers. You want Perl to produce different random numbers each time. This is important in nearly every application of random numbers, especially games. DiscussionMaking random numbers is hard. The best that computers can do, without special hardware, is generate "pseudo-random" numbers, which are evenly distributed in their range of values. These are generated using a mathematical formula, which means that given the same seed (starting point), two programs will produce identical pseudo-random numbers.
The
If you haven't called srand( <STDIN> ); Just because Perl tries to use a good default seed does not necessarily guarantee that the numbers generated are cryptographically secure against the most intrepid crackers. Textbooks on cryptography are usually good sources of cryptographically secure random number generators. See Also
The Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|