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:
+10
-1
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user