(-Peter-) wrote:
> Hi..
>
> I'm programming a Monte Carlo problem where i need to show that my
> results are reproducible - that is I need to prove this by running by
> program with seeded random numbers.
>
> The program is build up of a main method and a lot of other sub-
> routines. How can I create a random number generator, from which I can
> get my seeded random numbers. It shall be possible to get one random
> number at a time a lot times (some millions), and I need to call the
> random number generator from any of the subroutines and get the same
> sequence of numbers no matter from which routines i call them (also
> shifting between the sub-routines for example 5 calls from routine 1
> followed by 5 from the main routine should give the same numbers as if
> I called the generator 4 times from the main routine followed by 5
> times from routine number 10 followed by one call from the main
> routine again)
Create as many different java.util.Random objects as you
need, using the same seed value for each:
long seed = 123456789; // or whatever
Random rmain = new Random(seed);
Random rsub1 = new Random(seed);
...
Devote one Random object to each "subroutine" or group of
related subroutines, so each "subroutine" obtains values only
from its own Random object.
... but I may have misunderstood just what you mean by "the
same sequence." If it seems I have, please try to explain it
more clearly.
--