Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7220 Discussions

Persistance of random number generator state

Thomas_H_4
Beginner
377 Views
I am used to old fashioned Fortran code where I saved the state of my random number generators by putting the current seed/state into a common block. Rather than run a bunch of tests, I would like to ask here how do I maintain persistance of the random number generators? I need to generate a large number of random numbers for Monte Carlo ray tracing, but the number of random numbers required for each ray is unknown ahead of time. In my legacy code, I just save the seed/state in a common block and call a random number generator from within the subroutine that makes the Monte Carlo decision and using the seed to get a new random number. Do the "streams" need to be maintained in a common block or passed through my chains of subroutine arguments in order to maintain persistance and independence of the random numbers?

Thanks very much!
0 Kudos
1 Reply
Andrey_N_Intel
Employee
377 Views

VSLhas functions vslsavestreamf/vslloadstreamf for storing/restoring descriptive data of random stream to and from binary files. They may be very useful in time consuming Monte Carlo simulations.

You also might want to use vslcopystream (or vslcopystreamstate) functions to store copy of the random stream (or its state) in memory.

More details about storing/restoring random streams are available in MKL Manual and VSL Notes. I do not have all details regarding to your application; however, it appears that it is not required to hold random stream in a common block to maintain persistence as library service functionality mentioned above helps to do this.
Does it answer your question?

Thanks,
Andrey

0 Kudos
Reply