Commit db9dfd00 authored by cutealien's avatar cutealien

- Resetting Randomizer with 0 or no longer breaks it (will be set to 1). Same...

- Resetting Randomizer with 0 or no longer breaks it (will be set to 1). Same for other numbers for which it wasn't defined.
- Randomizer now returns range 0..randMax as documented and no longer 1..randMax as it did before. randMax got reduced by 1.
- Using now same random numbers as std::minstd_rand0. Not sure if the others were wrong, but documentation mentioned they are for mixed linear congruential generator from L'Ecuyer and as far as I can see we don't use that (that one mixes 2 calculations). We seem to use just a linear congruential generator. (I'm no expert on all this, just what it looks like from net articles).


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5243 dfc29bdd-3216-0410-991c-e03cc46cb475
parent cf1a56cb
-------------------------- --------------------------
Changes in 1.9 (not yet released) Changes in 1.9 (not yet released)
- Randomizer now returns range 0..randMax as documented and no longer 1..randMax as it did before. randMax got reduced by 1.
- Resetting Randomizer with 0 or no longer breaks it (will be set to 1). Same for other numbers for which it wasn't defined.
- Add SMaterialLayer::TextureWrapW for cubemap texture wrap mode at W axis. - Add SMaterialLayer::TextureWrapW for cubemap texture wrap mode at W axis.
- Add cubemap texture support for D3D9 and OpenGL drivers. - Add cubemap texture support for D3D9 and OpenGL drivers.
- Do no longer re-calculate md2 frames when they don't change (thx @npc for reporting) - Do no longer re-calculate md2 frames when they don't change (thx @npc for reporting)
......
...@@ -196,7 +196,7 @@ namespace os ...@@ -196,7 +196,7 @@ namespace os
// our Randomizer is not really os specific, so we // our Randomizer is not really os specific, so we
// code one for all, which should work on every platform the same, // code one for all, which should work on every platform the same,
// which is desireable. // which is desirable.
s32 Randomizer::seed = 0x0f0f0f0f; s32 Randomizer::seed = 0x0f0f0f0f;
...@@ -205,10 +205,10 @@ namespace os ...@@ -205,10 +205,10 @@ namespace os
{ {
// (a*seed)%m with Schrage's method // (a*seed)%m with Schrage's method
seed = a * (seed%q) - r* (seed/q); seed = a * (seed%q) - r* (seed/q);
if (seed<0) if (seed<1)
seed += m; seed += m;
return seed; return seed-1; // -1 because we want it to start at 0
} }
//! generates a pseudo random number //! generates a pseudo random number
...@@ -225,7 +225,12 @@ namespace os ...@@ -225,7 +225,12 @@ namespace os
//! resets the randomizer //! resets the randomizer
void Randomizer::reset(s32 value) void Randomizer::reset(s32 value)
{ {
seed = value; if (value<0)
seed = value+m;
else if ( value == 0 || value == m)
seed = 1;
else
seed = value;
} }
......
...@@ -43,8 +43,8 @@ namespace os ...@@ -43,8 +43,8 @@ namespace os
}; };
// mixed linear congruential generator (MLCG) // congruential pseudo-random generator
// numbers chosen according to L'Ecuyer, Commun. ACM 31 (1988) 742 // numbers identical to std::minstd_rand0
// period is somewhere around m-1 // period is somewhere around m-1
class Randomizer class Randomizer
{ {
...@@ -59,17 +59,18 @@ namespace os ...@@ -59,17 +59,18 @@ namespace os
//! generates a pseudo random number in the range 0..1 //! generates a pseudo random number in the range 0..1
static f32 frand(); static f32 frand();
//! get maxmimum number generated by rand() //! get maximum number generated by rand()
static s32 randMax(); static s32 randMax();
private: private:
static s32 seed; static s32 seed;
static const s32 m = 2147483399; // a non-Mersenne prime
static const s32 a = 40692; // another spectral success story static const s32 m = 2147483647; // a Mersenne prime (2^31-1)
static const s32 a = 16807; // another spectral success story
static const s32 q = m/a; static const s32 q = m/a;
static const s32 r = m%a; // again less than q static const s32 r = m%a; // again less than q
static const s32 rMax = m-1; static const s32 rMax = m-2;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment