libcoyotl - A Library of C++ Tools

Created by Scott Robert Ladd at Coyote Gulch Productions.


Public Member Functions | Protected Attributes | List of all members
libcoyotl::prng Class Reference

An abstract definition of a peudorandom number generator. More...

#include <prng.h>

Inheritance diagram for libcoyotl::prng:
libcoyotl::cmwc4096 libcoyotl::kissrng libcoyotl::mtwister libcoyotl::mwc1038 libcoyotl::mwc256

Public Member Functions

 prng ()
 Default constructor, reading seed from/dev/urandom or the time.
 prng (uint32_t seed)
 Default constructor, with optional seed.
virtual void init (uint32_t seed)
 Initializes the generator with "seed".
uint32_t get_seed ()
 Returns the original seed value.
virtual uint32_t get_rand ()=0
 Get the next integer.
uint32_t get_rand_range (uint32_t lo, uint32_t hi)
 Get the next integer in the range [lo,hi].
size_t get_rand_index (size_t length)
 Get the next random value as a size_t index.
double get_rand_real1 ()
 Get the next number in the range [0,1].
double get_rand_real2 ()
 Get the next number in the range [0,1)
double get_rand_real3 ()
 Get the next number in the range (0,1)
double get_rand_real53 ()
 Get the next number in the range [0,1)

Protected Attributes

uint32_t m_seed
 Initialization seed.

Detailed Description

This class defines the generic properties of any psuedo-random number generator that returns a 32-bit unsigned result.

Constructor & Destructor Documentation

libcoyotl::prng::prng ( )

The constructor initializes the prng seed from either the time or some stochastic source such as /dev/random or /dev/urandom.

libcoyotl::prng::prng ( uint32_t  seed)

Starts the PRNG with a specific seed; this is provided so that a given sequence of "random" values can be duplicated. Note that the actual sequence is predicated on the specific PRNG algorithm.

Parameters
seed- Seed value used to "start" or seed the generator

Member Function Documentation

virtual uint32_t libcoyotl::prng::get_rand ( )
pure virtual

Returns the next uint32_t in sequence.

Returns
A pseudorandom uint32_t value

Implemented in libcoyotl::mwc1038, libcoyotl::mtwister, libcoyotl::cmwc4096, libcoyotl::mwc256, and libcoyotl::kissrng.

Referenced by get_rand_real1(), get_rand_real2(), and get_rand_real3().

size_t libcoyotl::prng::get_rand_index ( size_t  length)
inline

Returns the next value as a size_t "index" in the range [0,length).

Parameters
length- Maximum value of result
Returns
A pseudorandom size_t value

References get_rand_real2().

uint32_t libcoyotl::prng::get_rand_range ( uint32_t  lo,
uint32_t  hi 
)
inline

Returns the next int_value between lo and hi, inclusive.

Parameters
lo- Minimum value of result
hi- Maximum value of result
Returns
A pseudorandom uint32_t value

References get_rand_real2().

double libcoyotl::prng::get_rand_real1 ( )
inline

Returns the next real number in the range [0,1], i.e., a number greater than or equal to 0 and less than or equal to 1. Provides 32-bit precision.

Returns
A pseudorandom double value

References get_rand().

double libcoyotl::prng::get_rand_real2 ( )
inline

Returns the next real number in the range [0,1), i.e., a number greater than or equal to 0 and less than 1. Provides 32-bit precision.

Returns
A pseudorandom double value

References get_rand().

Referenced by get_rand_index(), and get_rand_range().

double libcoyotl::prng::get_rand_real3 ( )
inline

Returns the next real number in the range (0,1), i.e., a number greater than 0 and less than 1. Provides 32-bit precision.

Returns
A pseudorandom double value

References get_rand().

double libcoyotl::prng::get_rand_real53 ( )

Returns the next real number in the range [0,1), i.e., a number greater than or equal to 0 and less than 1. Provides 53-bit precision.

Returns
A pseudorandom double value
uint32_t libcoyotl::prng::get_seed ( )
inline

Returns the seed value used to initialize this generator.

Returns
The seed value used to initialize this generator

References m_seed.

virtual void libcoyotl::prng::init ( uint32_t  seed)
virtual

Resets the generator using the provided seed value.

Parameters
seed- Seed value used to "start" or seed the generator

Reimplemented in libcoyotl::mwc1038, libcoyotl::mtwister, libcoyotl::cmwc4096, libcoyotl::mwc256, and libcoyotl::kissrng.


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

© 1996-2005 Scott Robert Ladd. All rights reserved.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.