Random number generators discussion

Random number generators | www.agner.org

How to get the seed from a running random process?
Author: Agner Date: 2010-07-19 06:59
To save the state of the random number generator, you need to save all the data. Use a C++ version (or C++ interface to an assembly language version) and save all data defined in the class to a binary file. These data are private or protected so you need to make a member function to save the data and another member function to restore the data. For example:

class CRandomMersenne {
...
public:
void SaveToFile(FILE * f) {
   fwrite(mt, sizeof(uint32_t), MERS_N, f);
   fwrite(&mti, sizeof(int), 1, f);
   fwrite(&LastInterval, sizeof(uint32_t), 1, f);
   fwrite(&RLimit, sizeof(uint32_t), 1, f);
}
void RecoverFromFile(FILE * f) {
   fread(mt, sizeof(uint32_t), MERS_N, f);
   fread(&mti, sizeof(int), 1, f);
   fread(&LastInterval, sizeof(uint32_t), 1, f);
   fread(&RLimit, sizeof(uint32_t), 1, f);
}
};

Remember to open the file in binary mode and to close it again.

 
thread How to get the seed from a running random process? new - Thuy Nguyen - 2010-07-19
last reply How to get the seed from a running random process? - Agner - 2010-07-19