Added some checks for invalid numbers to love.math.setRandomState

--HG--
branch : RandomGenerator-2
This commit is contained in:
Alex Szpakowski
2013-08-04 17:04:52 -03:00
parent 0447d1e7c5
commit 674ad9247a
4 changed files with 52 additions and 13 deletions
+9
View File
@@ -45,6 +45,15 @@ RandomGenerator::RandomGenerator()
#endif
}
void RandomGenerator::setState(RandomGenerator::State state)
{
// 0 xor 0 is still 0, so Xorshift can't generate new numbers.
if (state.b64 == 0)
throw love::Exception("Invalid random state.");
rng_state = state;
}
uint64 RandomGenerator::rand()
{
rng_state.b64 ^= (rng_state.b64 << 13);