Bug in MRandomLCG
by Tom Spilman · in Torque Game Engine · 10/30/2006 (6:01 pm) · 0 replies
I found something interesting in MRandomLCG::randI()...
if ( mSeed <= msQuotient )
mSeed = (mSeed * 16807L) % S32_MAX;
... by this method if mSeed is ever zero, either by calling setSeed( 0 ) or by a previous random result, the generator will continue to return zeros until the seed is changed.
This seems to be a really bad thing... either mSeed needs to be protected from being zero or mSeed needs to be incremented before the multiply.
if ( mSeed <= msQuotient )
mSeed = (mSeed * 16807L) % S32_MAX;
... by this method if mSeed is ever zero, either by calling setSeed( 0 ) or by a previous random result, the generator will continue to return zeros until the seed is changed.
This seems to be a really bad thing... either mSeed needs to be protected from being zero or mSeed needs to be incremented before the multiply.
About the author
Tom is a programmer and co-owner of Sickhead Games, LLC.