#5657 - sgeos - Mon May 05, 2003 4:58 am
Has anyone come across a method of generating an RNG with an exact period? I'm looking for a way to setup RNGs on the fly with function call something like the following:
next_state = rng(current_state, period);
states range from 0 to period - 1. I'm not sure if Knuth covers this. At any rate, I don't have my books with me.
There is a way to generate LCGs that meet all the above criteria except that the output isn't random. Take:
r = m + 1; /* Or any multiple of m, plus one */
c = 1;
next_state = (current_state * r + c) % m;
-Brendan
next_state = rng(current_state, period);
states range from 0 to period - 1. I'm not sure if Knuth covers this. At any rate, I don't have my books with me.
There is a way to generate LCGs that meet all the above criteria except that the output isn't random. Take:
r = m + 1; /* Or any multiple of m, plus one */
c = 1;
next_state = (current_state * r + c) % m;
-Brendan