Many languages allow you to "seed" the random number generator with a given number. Random numbers generated will be the same, given the same seed. In order to make something unpredictably random, you generally pass the current system time in as the seed.
Why would you need this? Here's an example:
Sariat asked about character generation for his Super Hero Bash. Someone brought up random stat generation, saying people could keep generating over and over until they get what they want. It would nice in this case to divide world.realtime by, say 36,000 (number of ticks in an hour), pass the result into rand_seed, and have the same randomly generated hero produced if someone re-generated, unless they waited an hour.
Or suppose you wanted a function that would return a random fantasy-type name that the user could not change. You might want to take the player's key, add up the ascii values of the letters in the name, and pass the result into rand_seed. The fantasy name proc could do some fancy stuff, randomizing somewhat, and given key X, always return name Y.
I know these are kind of unusual examples, but I'm sure I could come up with more useful if needed.
What do you think?
Oct 16 2001, 1:38 am