store old state of random generator to restore after a seed()

The light calculation requires the random generator to be seeded with a
constant - otherwise repeated light recalculations would make the lights
change.

This patch allows the random generator to go back to the state before the
static seed().
This commit is contained in:
ac-stef
2015-02-08 17:39:14 +01:00
parent 05a41b1c0a
commit 685dbb8326
3 changed files with 13 additions and 4 deletions
+10 -1
View File
@@ -849,11 +849,12 @@ bool checkchallenge(const char *answerstr, void *correct)
#define M (397)
#define K (0x9908B0DFU)
static uint state[N];
static uint state[2 * N];
static int next = N;
void seedMT(uint seed)
{
loopi(N) state[i + N] = state[i];
state[0] = seed;
for(uint i = 1; i < N; i++)
state[i] = seed = 1812433253U * (seed ^ (seed >> 30)) + i;
@@ -877,3 +878,11 @@ uint randomMT()
return y;
}
void popMT() // undo last seedMT()
{
loopi(N) state[i] = state[i + N];
}
#undef N
#undef M
#undef K