Random number generators discussion

Random number generators | www.agner.org

 
thread Repeat sequence of random number - Manojit Roy - 2007-08-21
last reply Repeat sequence of random number - Agner - 2007-08-28
 
Repeat sequence of random number
Author:  Date: 2007-08-21 18:57
Dear Agner,
Thank you for making your random number codes available to us. I have a question. I am trying to generate a sequence of random numbers repeatedly in a loop, by using the same seed. But I cannot create same instance multiple times; for example:

for(int i=0;i<10;i++){
seed = 123456789;
StochasticLib1 sto(seed);
}

does not work. Is there a simple way of doing this?
Thanks again.

   
Repeat sequence of random number
Author: Agner Date: 2007-08-28 10:47
Manojit Roy wrote:
for(int i=0;i<10;i++){
seed = 123456789;
StochasticLib1 sto(seed);
}

does not work.

This should work if you generate random numbers inside the i loop after creating the instance.

If your compiler cannot generate a new instance inside the loop then use sto.RandomInit(seed);