ID:137538
 
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?
This would have been great for a random map generator I was working on. Players could have kept track of seed numbers they liked and reused them to get the same map. I seem to remember a couple of old games that used this system. (Populus maybe?)
Skysaw wrote:

What do you think?

I've never really liked the default behavior for rand() in most languages, which was to assume a fixed, reproducible sequence (no seed) unless given otherwise. As you mentioned, 99% of the time (100% for me) you want to do rand_seed([clock time]) to get a reasonably random pattern, so we chose to make that the default in DM. Well, actually as you noticed it's the only way in DM.

Of course, if you really want to have a fixed semirandom pattern, it's fairly straightforward to soft-code it. In fact, it's a rather interesting problem, I think. Basically, how does one map a seed value (say, some function of the time) to a frequently fluctuating set of values with a long period. I think DM supports enough mathematical operations to do this without too much effort. It's contest-worthy!

That said, it would certainly be trivial to provide a seed function, so I suppose we ought to do it.
In response to Tom
Tom wrote:
Skysaw wrote:

What do you think?

I've never really liked the default behavior for rand() in most languages, which was to assume a fixed, reproducible sequence (no seed) unless given otherwise. As you mentioned, 99% of the time (100% for me) you want to do rand_seed([clock time]) to get a reasonably random pattern, so we chose to make that the default in DM. Well, actually as you noticed it's the only way in DM.

Of course, if you really want to have a fixed semirandom pattern, it's fairly straightforward to soft-code it. In fact, it's a rather interesting problem, I think. Basically, how does one map a seed value (say, some function of the time) to a frequently fluctuating set of values with a long period. I think DM supports enough mathematical operations to do this without too much effort. It's contest-worthy!

That said, it would certainly be trivial to provide a seed function, so I suppose we ought to do it.

Well I certainly don't mind the default behavior, since that's what I want 99% of the time, but it's nice to be able to override. I'll make it an official request. :-)

I never tried to code a random number generator myself, though I suppose I could figure it out.
In response to Tom
Of course, if you really want to have a fixed semirandom pattern, it's fairly straightforward to soft-code it.

Hmm... [link]

You're consistent, I'll give you that! :)

I guess I'll see if I can find some links... Okay, this looks good and has some more links to related sites. Looks like you may be right--it might indeed be a fun little thing to code in DM!

http://www.howstuffworks.com/question697.htm