Another Random question...
by Eric Stout · in Torque Game Builder · 03/13/2005 (12:11 pm) · 18 replies
Just curious as to what formula T2D uses for random numbers... And if the result sets are consistant across platforms/cpu's... I wasn't aware that this could be an issue until it came up with Blitz3D (and the other blitz products). Mark mentioned that it might not be, and wouldn't guarantee it, and had some odd rationalization behind it. I did research and wrote a dll and a link module using the Mersenne Twist method of PRNG for blitz which I'm sure IS consistant... But I'm gunshy now about cross/platform game making tools and whether they are consistant as well...
Eric Stout
Eric Stout
#2
03/13/2005 (7:18 pm)
So it IS possible that seed 'X' could result in differing sets on MacOSX than on the PC? Hrm... Might have to replace that mRandom.cc with some mersenne twist code.......
#3
03/13/2005 (8:06 pm)
Replacing it should be trivial. The Mersenne code is drop-in, pretty much. I used it in my 2D engine from a while back.
#4
It's only a problem if you need strict determinism. Other than that, why would it be a problem?
- Melv.
03/14/2005 (12:46 am)
I have no idea, you'd have to tell me. I've never looked at that particular problem. It was never a problem for all the applications developed with it over the last several years.It's only a problem if you need strict determinism. Other than that, why would it be a problem?
- Melv.
#5
SSI had a game called Dungeon Hack which was basically a roguelike with goldbox type graphics. At the beginning of the game dungeons, mobs, etc were all created based on a random seed. Unlike most roguelikes this seed was given to the player to write down. Then they could send that seed to all of their friends to play the same exact dungeon or for them to play the same dungeon over again later. (I'm sure you could see the multiplayer possibilities of this as well)... Elite also based it's huge galaxy on a random number generated result set and was exactly the same across platforms (this game got translated to dozens of 8bit platforms). If the random number generator isn't consistant across platforms/cpu's then games like these that might take advantage of multiplayer possibilities cannot guarantee the same galaxy, dungeon, monster generation, damage from mobs, etc.
It's easy enough to switch the random number generator in T2D, but you might want to do it yourself to guarantee consistant result sets. If T2D and I'm assuming TGE as well weren't cross platform it really wouldn't be a big issue, though the possibility of there being differences between Intel and AMD chips does exist with a PRNG based on register values.
03/14/2005 (11:05 am)
Well, the idea that there might be an issue came up with someone writing an encryption algorithm based on a seed passed to the random number generator... And then once it got to being discussed, also carried over to games like a roguelike game. SSI had a game called Dungeon Hack which was basically a roguelike with goldbox type graphics. At the beginning of the game dungeons, mobs, etc were all created based on a random seed. Unlike most roguelikes this seed was given to the player to write down. Then they could send that seed to all of their friends to play the same exact dungeon or for them to play the same dungeon over again later. (I'm sure you could see the multiplayer possibilities of this as well)... Elite also based it's huge galaxy on a random number generated result set and was exactly the same across platforms (this game got translated to dozens of 8bit platforms). If the random number generator isn't consistant across platforms/cpu's then games like these that might take advantage of multiplayer possibilities cannot guarantee the same galaxy, dungeon, monster generation, damage from mobs, etc.
It's easy enough to switch the random number generator in T2D, but you might want to do it yourself to guarantee consistant result sets. If T2D and I'm assuming TGE as well weren't cross platform it really wouldn't be a big issue, though the possibility of there being differences between Intel and AMD chips does exist with a PRNG based on register values.
#6
03/14/2005 (12:38 pm)
Hehe..what's ironic is that this exact deterministic issue with random number generators is why people are still trying to figure out how to generate true chaos generation algorithms that can be used properly. Most people do not want deterministic random number generators--they are supposed to be random! For the cases where you want deterministic "random" number sets, then use a deterministic algorithm!
#7
@Stephen: Oh sweet irony. :)
*yike, steps out the room*.
- Melv.
03/14/2005 (12:55 pm)
@Eric: I understand where you're coming from now. :) If you want to submit some code that you implement to handle such a thing then I'd be all ears.@Stephen: Oh sweet irony. :)
*yike, steps out the room*.
- Melv.
#8
Thanks for taking a look. :)
Kanati
03/14/2005 (1:24 pm)
Email sent to your address with the code I used to implement the MT in blitz. Thanks for taking a look. :)
Kanati
#10
Everything is based on a repeating formula. The randomness as people call it, comes from external stimuli. As a result of this a closed system (without external stimuli) is never random in any sense of the word and guess what....the universe is a closed system :o)
Think of the universe as a shaken snow globe, which is slowly settling over time....Er on second thoughts don't! Unless you want to move in the direction of quantum physics, subspace, matter generation at sub atomic levels, butterfly effects etc etc. Just take it as read that nothing is truly random....
03/15/2005 (4:37 am)
Mathematically speaking "What is random?" Everything is based on a repeating formula. The randomness as people call it, comes from external stimuli. As a result of this a closed system (without external stimuli) is never random in any sense of the word and guess what....the universe is a closed system :o)
Think of the universe as a shaken snow globe, which is slowly settling over time....Er on second thoughts don't! Unless you want to move in the direction of quantum physics, subspace, matter generation at sub atomic levels, butterfly effects etc etc. Just take it as read that nothing is truly random....
#11
*too much coffee*
- Melv.
03/15/2005 (5:40 am)
@Peter: STOP SHAKING MY UNIVERSE!!!! Oh the snow, it's always falling. I wonder what is beyond the glass?*too much coffee*
- Melv.
#12
03/15/2005 (6:02 am)
I think the bigger question is, who shook the snow globe, and why? :)
#13
It's supposed to be 4 times faster than libc's rand() function.
03/15/2005 (8:56 am)
Here's a pretty performant version of a MT c++ class. www-personal.engin.umich.edu/~wagnerr/MersenneTwister.htmlIt's supposed to be 4 times faster than libc's rand() function.
#17
05/02/2005 (9:57 pm)
I noticed that .2 has something in the change log about the random number generator... did you guys implement the mersenne twist or something else deterministic?
#18
Why is this valuable? Networking.
If you're running a real-time networked game such that you are relying on strict synchonisity between multiple machines (admittedly, probably not something you'd want to touch with a 10-foot pole on a PC, but on a console it is perfectly viable), you need to be able to generate the same random numbers on each machine. This is the equivalent of server-side data. At the same time, you want to be able to have client-side random numbers for things like particle effects. That way, each machine could, in theory, be running different levels of trivial effects, but they could still be synchronized correctly.
Admittedly a minor use, but it would also be a minor change to T2D. Effectively, it is adding the ability to create random number generator class objects and calling them accordingly.
As for the RNGs mentioned in this thread, I have to say I prefer the Mersenne Twister. When I want a random number, I really want the bits randomized, even if it takes a bit more time to do it. Especially when I'm going to throw away some number of bits to produce a random number on a range.
05/02/2005 (10:59 pm)
Here's an idea: multiple instances of a random number generator.Why is this valuable? Networking.
If you're running a real-time networked game such that you are relying on strict synchonisity between multiple machines (admittedly, probably not something you'd want to touch with a 10-foot pole on a PC, but on a console it is perfectly viable), you need to be able to generate the same random numbers on each machine. This is the equivalent of server-side data. At the same time, you want to be able to have client-side random numbers for things like particle effects. That way, each machine could, in theory, be running different levels of trivial effects, but they could still be synchronized correctly.
Admittedly a minor use, but it would also be a minor change to T2D. Effectively, it is adding the ability to create random number generator class objects and calling them accordingly.
As for the RNGs mentioned in this thread, I have to say I prefer the Mersenne Twister. When I want a random number, I really want the bits randomized, even if it takes a bit more time to do it. Especially when I'm going to throw away some number of bits to produce a random number on a range.
Associate Melv May
Kirkpatrick, S., and E. Stoll, 1981; A Very Fast Shift-Register
Sequence Random Number Generator, Journal of Computational Physics,
V. 40.
Maier, W.L., 1991; A Fast Pseudo Random Number Generator,
Dr. Dobb's Journal, May, pp. 152 - 157
Period = 2^249
R250
All TGE products use this. You have the code so you can look in "mRandom.cc/h".
I would say that it would only be a problem if you were relying on a some kind of determinism based upon a seeded value although there may be other scenarios I've not thought of.
- Melv.