Open Babel  3.0
Public Member Functions | List of all members
OBRandom Class Reference

#include <openbabel/rand.h>

Public Member Functions

 OBRandom (bool useSys=false)
 
void Seed (int seed)
 
void TimeSeed ()
 
int NextInt ()
 
double NextFloat ()
 

Detailed Description

Random number generator.

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

Constructor & Destructor Documentation

◆ OBRandom()

OBRandom ( bool  useSys = false)

Constructor. useSys will use the system rand() function.

Member Function Documentation

◆ Seed()

void Seed ( int  seed)
inline

Use seed for the random number generator seed.

◆ TimeSeed()

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

Referenced by OBForceField::GenerateVelocities(), OBConformerSearch::OBConformerSearch(), OBRandom::OBRandom(), OBForceField::RandomRotorSearchInitialize(), OBRandom::Seed(), OBConformerSearch::Setup(), and OBForceField::WeightedRotorSearch().

◆ NextInt()

int NextInt ( )

◆ NextFloat()

double NextFloat ( )
Returns
a random floating-point number between 0.0 and 1.0

Referenced by OBForceField::GenerateVelocities(), vector3::randomUnitVector(), OBRandom::Seed(), and OBForceField::WeightedRotorSearch().


The documentation for this class was generated from the following files: