Random Numbers
From TDN
|
[edit] Random Number GeneratorsAll of the Torque Game Engine derivatives use the same two algorithm for generating random numbers. You have the code so you can look in engine/math/mRandom.cc/h. [edit] Linear Congruential MethodA Linear Congruential Generator (LCG) is a simple but well known algorithm for random number generation.
[edit] R250 AlgorithmR250 is a higher quality RNG algorithm, that is comparable in speed and quality to the 'Mersenne Twister'. Torque's R250 algorithm appears to use the LCG implementation(above) to seed itself.
A Fast Pseudo Random Number Generator,
[edit] Other Considerations- "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. [edit] Using the RNGs in Torque(stub: Inro) [edit] MRandomLCG(stub: short tutorial and code samples of how to correctly used Torque's built in RNG's - needed here)
[edit] MRandomR250(stub: short tutorial and code samples needed; I started it but could be expanded! ~SP) Judging from other examples in the code the R250 may be the easier/better RNG to use. It's a two step process:
The MRandom250 is seeded and initlized for you by the constructor. If passed no arguments, it generates a low-quality random seed to initialize itself. You can optionally pass it a seed to your own liking. (Personally, i'm not sure which is preferable ~SP). MRandomR250 mRandom1; // Default Constructor called. U32 x = mRandom1.randI(); U32 seed = Platform::getRealMilliseconds(); MRandomR250 mRandom2(seed); // Use the seed I give you. U32 x = mRandom2.randI();
|



