Advertisement

Seed Numbers

Started by March 04, 2000 11:39 PM
3 comments, last by Possibility 24 years, 6 months ago
I have heard that many games use a seed number for their random numbers. Like for a game like civilization, a large seed number is generated at the begining of the turn. And each time a random number is used, the last number of the seed is used, and then the seed is devided by 10. But for a game like civilization, a random number could be used like upto 1000 times a turn. But you cant generate a 1000 digit long interger. So how do games use seed numbers when they can only be ten digits long (which is basically only ten random numbers). If the seed number is to short, when it is used up, is a new generated? and if so, then what is the point of using random numbers, and why not just generate a new random number each time you need one? I would appreciate any help for this using C++. Thanks Possibility pull0017@tc.umn.edu
I''m not sure, but I think that you might be slightly mistaken in the way that you think random number generation works. A common and simple technique that is used to generate random numbers does include a division (actually a ''remainder'') but that is not the only step.

A simple random number generator works something like this:
1) Choose two large integers (gen1 and gen2) such that one is double the other.
2) Choose a seed value that is between 1 and the smaller of these 2 integers.
3) Choose a value (Max) that is the largest number to be returned.
4) For each iteration, multiply gen1 by the seed and then add gen2. The new seed is the remainder of this number divided by Max.
5) Return the seed as the ''random'' value.

This of course, isn''t really random but no computer generated techniques truly are. This sequence will repeat after Max iterations and also tends to fall into somewhat of a pattern. However, if you want a simple pseudo-random number generator, something like this would be the way to go. (or just use srand() and rand() or srandom() and random() which are already written for you. )

I hope that helps. If you''re still curious about it, you can probably find info on random number generation by doing a search on Yahoo or similar.
Advertisement
yah, i know how to use:
srand(time(0));
number = rand () % 10;


But the developers to the game Age of Wonders told me that in that game, at the begining of each turn, a SEED number is generated, and that number is used for all evaluations where a random number is need. For example, say the seed number is 314159
And a swordsmen attacks an archer, he has a say 60% chance to hit the archer, so instead of using the srand/rand as shown above, they instead use the last number of the seed number, in this case that is a 9, so the swordsmen has a successfull hit. The swordsmen has 2 attacks, so he swings again, and then the 5 is used from the seed number, so the swordsmen misses.

This is the particular kind of seed number i am refering too. Because in this game, a random number (always between 0 and 9) maybe needed over a thousand times a turn, and no form of interger can be 1000 digits long. A 32bit interger is only 10 digits long. So I was just wondering how exactly games like Age of Wonders and Civilization work with there seed numbers that they generate at the begining of each turn for the random events that will occur on that turn.

Possibility
Maybe they are performing some check every time they get a new number and if their old seed has been ''divided away'' they generate a new one with a call to rand() or something similar? It wouldn''t be hard to check when using integers since dividing anything less than 10 by 10 would give you a result of zero.

I''m not quite sure what purpose this serves though. Generating a new number isn''t much slower than dividing by 10, so why not just call rand() every time? It just seems like extra work for very little gain.
Well, that is exactly what i was thinking. I say just use rand() each time you need random number. But someone (including the developers of aow) told me they use a seed that is generating at the begining of turn. But oh well.
Thanks for the info anyways.

Possibility

This topic is closed to new replies.

Advertisement