#include <openbabel/rand.h>
Public Member Functions | |
OBRandom (bool useSys=false) | |
void | Seed (int seed) |
void | TimeSeed () |
int | NextInt () |
double | NextFloat () |
The OBRandom class can be used to facilitate cross-platform random number generation. The class can be set to specific seed states, or set to use the current time or other arbitrary data as a seed.
OBRandom generator; // Don't use system rand() functions generator.TimeSeed(); // initialize from the current time cerr << " New Random Integer " << generator.NextInt() << endl; cerr << " New Random Floating-Point " << generator.NextFloat() << endl;
Alternatively, OBRandom can be used as an interface to the system random number generator.
OBRandom generator(true); // Use system rand() functions generator.Seed(10246);// Use a specific initial seed value for reproducing sequence
OBRandom | ( | bool | useSys = false |
) |
Constructor. useSys
will use the system rand() function.
void Seed | ( | int | seed | ) | [inline] |
Use seed
for the random number generator seed.
void TimeSeed | ( | ) |
Use the current time for the random number generator seed If sranddev is available (e.g., Mac OS X, BSD...) use this instead for more random seeds
int NextInt | ( | ) |
double NextFloat | ( | ) |