ROSE  0.9.6a
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LinearCongruentialGenerator Class Reference

Linear congruential generator. More...

#include <LinearCongruentialGenerator.h>

Public Member Functions

 LinearCongruentialGenerator ()
 Initialize the generator with a random seed. More...
 
 LinearCongruentialGenerator (int seed)
 Initialize the generator with a seed. More...
 
void init ()
 Random initialization. More...
 
void reset ()
 Reset the sequence back to the first value. More...
 
void reseed (int seed)
 Start a new sequence of random values. More...
 
int seed () const
 Return the seed for the current sequence. More...
 
uint64_t again () const
 Return the last returned value again. More...
 
uint64_t max ()
 Return the maximum possible value. More...
 
bool flip_coin ()
 Return a random boolean value. More...
 
uint64_t next (size_t nbits=64, size_t niter=1)
 Return the next value in the sequence. More...
 
uint64_t operator() ()
 Return the next value in the sequence. More...
 

Protected Attributes

int seed_
 
uint64_t value_
 

Detailed Description

Linear congruential generator.

Generates a repeatable sequence of pseudo-random numbers.

Definition at line 8 of file LinearCongruentialGenerator.h.

Constructor & Destructor Documentation

LinearCongruentialGenerator::LinearCongruentialGenerator ( )
inline

Initialize the generator with a random seed.

Definition at line 11 of file LinearCongruentialGenerator.h.

References init().

LinearCongruentialGenerator::LinearCongruentialGenerator ( int  seed)
inline

Initialize the generator with a seed.

The seed determines which sequence of numbers is returned.

Definition at line 14 of file LinearCongruentialGenerator.h.

Member Function Documentation

void LinearCongruentialGenerator::init ( )

Random initialization.

This uses /dev/urandom or /dev/random to initailize the sequence.

Referenced by LinearCongruentialGenerator().

void LinearCongruentialGenerator::reset ( )
inline

Reset the sequence back to the first value.

Definition at line 20 of file LinearCongruentialGenerator.h.

References seed_, and value_.

void LinearCongruentialGenerator::reseed ( int  seed)
inline

Start a new sequence of random values.

The seed identifies which sequence is returned.

Definition at line 23 of file LinearCongruentialGenerator.h.

References seed(), seed_, and value_.

int LinearCongruentialGenerator::seed ( ) const
inline

Return the seed for the current sequence.

Definition at line 26 of file LinearCongruentialGenerator.h.

References seed_.

Referenced by reseed().

uint64_t LinearCongruentialGenerator::again ( ) const
inline

Return the last returned value again.

Definition at line 29 of file LinearCongruentialGenerator.h.

References value_.

uint64_t LinearCongruentialGenerator::max ( )

Return the maximum possible value.

uint64_t LinearCongruentialGenerator::next ( size_t  nbits = 64,
size_t  niter = 1 
)

Return the next value in the sequence.

If nbits is specified, then only the low-order bits are randomized and the high order bits are always cleared. For instance, to get only positive values for casting to a 32-bit signed integer, use nbits=31. The niter indicates the number of values that should be consumed, all of which are exclusive-ORed together to create the return value. If niter is zero this function returns zero without consume any values.

Referenced by operator()().

uint64_t LinearCongruentialGenerator::operator() ( )
inline

Return the next value in the sequence.

If nbits is specified, then only the low-order bits are randomized and the high order bits are always cleared. For instance, to get only positive values for casting to a 32-bit signed integer, use nbits=31. The niter indicates the number of values that should be consumed, all of which are exclusive-ORed together to create the return value. If niter is zero this function returns zero without consume any values.

Definition at line 40 of file LinearCongruentialGenerator.h.

References next().

bool LinearCongruentialGenerator::flip_coin ( )

Return a random boolean value.

Member Data Documentation

int LinearCongruentialGenerator::seed_
protected

Definition at line 47 of file LinearCongruentialGenerator.h.

Referenced by reseed(), reset(), and seed().

uint64_t LinearCongruentialGenerator::value_
protected

Definition at line 48 of file LinearCongruentialGenerator.h.

Referenced by again(), reseed(), and reset().


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