views:

310

answers:

1

Hi,

Given that we start the call to the function ran2 with a negative integer [the seed] it will produce a series of random numbers. The sequence can be regenerated exactly if the same seed is used.

Now my question is that is there a way that we can directly enter into some point in the sequence and then continue from that point onwards ? For example if the random numbers for a certain seed are 0.35, 0.32, 0.44,0.32,0.66,0.32, 0.45.

If we know that seed which gave rise to this sequence, is there a way to get the function to return 0.66 and then continue from that point onwards?

The way I want to use it is in a simulation. Whereby if my simulation ends at a certain point and I need to restart it I should continue with the same sequence of random numbers. Thanks.

+1  A: 

I'd agree with @dirkgently's comment above. While I'm not familiar with ran2 specifically, based on this sample code it looks like there are a handful of stateful pieces (idum, idum2, iy and iv) that could be encapsulated out and stored. When you 'pause' your simulation you can save off this state and write it back into the ran2 engine the next time you start things up. Restoring the state information should put the machine right back where it left off, and the random sequence can resume. This may require a little modification of the ran2 code itself, but should not be a difficult change to fold in.

fbrereto
Yes, exactly. You'll have to save and restore everything that's declared `static` (which means moving them out to be file globals and adding save/restore functions) but that will permit you to pick up the sequence where it left off.
mtrw