GClasses
GClasses::GRand Class Reference

Detailed Description

This is a 64-bit pseudo-random number generator.

When subclassing it, overriding the next and setSeed methods will be sufficient. However, all of the methods are virtual, so you can give them more efficient or accurate versions if you wish.

#include <GRand.h>

Public Member Functions

 GRand (uint64_t seed)
 Create a new random number generator with the given seed. More...
 
 GRand (const GRand &that)
 Copy constructor. Throws an exception to prevent copying this object by value. More...
 
virtual ~GRand ()
 Destructor. More...
 
 f (x;\alpha,\beta)&
 Returns a random value from a beta distribution with parameters alpha and beta. More...
 
virtual uint64_t next ()
 Returns an unsigned pseudo-random 64-bit value. More...
 
virtual uint64_t next (uint64_t range)
 Returns a pseudo-random uint from a discrete uniform distribution in the range 0 to range-1 (inclusive). (This method guarantees the result will be drawn from a uniform distribution, whereas doing "next() % range" does not guarantee a truly uniform distribution.) More...
 
virtual void setSeed (uint64_t seed)
 Sets the seed. More...
 

Public Attributes

 x
 

Protected Attributes

uint64_t m_a
 
uint64_t m_b
 

Constructor & Destructor Documentation

GClasses::GRand::GRand ( uint64_t  seed)

Create a new random number generator with the given seed.

Parameters
seedthe seed to use for generating numbers from the random number generator
GClasses::GRand::GRand ( const GRand that)

Copy constructor. Throws an exception to prevent copying this object by value.

virtual GClasses::GRand::~GRand ( )
virtual

Destructor.

Member Function Documentation

GClasses::GRand::f ( x;\  alpha,
beta 
)

Returns a random value from a beta distribution with parameters alpha and beta.

(The following was pasted from wikipedia with a little editing)

The probability density function of the beta distribution is:

virtual uint64_t GClasses::GRand::next ( )
inlinevirtual

Returns an unsigned pseudo-random 64-bit value.

virtual uint64_t GClasses::GRand::next ( uint64_t  range)
virtual

Returns a pseudo-random uint from a discrete uniform distribution in the range 0 to range-1 (inclusive). (This method guarantees the result will be drawn from a uniform distribution, whereas doing "next() % range" does not guarantee a truly uniform distribution.)

Parameters
rangeone greater than the largest number that will be returned
virtual void GClasses::GRand::setSeed ( uint64_t  seed)
virtual

Sets the seed.

Note
If you subclass this, make sure you call the superclass version. Because the earlier code was not designed for subclassing, the GRand class is not abstract. Thus, if someone has passed a GRand object of your new type by value, they will get a copy of the sub-object with default behavior. To make their program work, the seed for the default generator needs to be set rather than being left uninitialized.

Member Data Documentation

uint64_t GClasses::GRand::m_a
protected
uint64_t GClasses::GRand::m_b
protected
GClasses::GRand::x
Initial value:
{\alpha-1}(1-x)^{\beta-1} \\[6pt]
& = \frac{1}{\mathrm{B}(\alpha,\beta)}\