Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes

YAPET::PWGEN::RNG Class Reference

class for interfacing random number generators. More...

#include <rng.h>

List of all members.

Public Member Functions

size_t getRandomNumber (size_t ceil) throw (PWGenException)
RNGENGINE getRNGEngineUsed () const throw ()
size_t operator() (size_t ceil) throw (PWGenException)
const RNGoperator= (const RNG &r) throw ()
 RNG (const RNG &r) throw (PWGenException)
 RNG (RNGENGINE request=AUTO) throw (PWGenException)
 Try a specific RNG Engine or use automatically determination.
virtual ~RNG () throw ()

Static Public Member Functions

static int getAvailableRNGs ()

Private Member Functions

size_t _lrand48 (size_t ceil) throw ()
size_t _rand (size_t ceil) throw ()
size_t devrandom (size_t ceil) throw (PWGenException)
 returns a random number using the kernel random number generator
void init_rng (RNGENGINE request) throw (PWGenException)
 Initializes the given engine.

Static Private Member Functions

static void check_availability () throw (PWGenException)

Private Attributes

int fd
 file descriptor
bool rng_initialized
 is rng initialized
RNGENGINE rng_used
 which rng is used

Static Private Attributes

static int rng_available = 0
 which rng are available

Detailed Description

Class for interfacing random number generators. It tries the following random generators:

The random numbers are in the range of size_t, since this is the range of the pool CharacterPool.

See also:
CharacterPool

Definition at line 71 of file rng.h.


Constructor & Destructor Documentation

RNG::RNG ( RNGENGINE  request = AUTO  )  throw (PWGenException)

Try to initialize the given RNG Engine.

If the AUTO Engine is requested (the default value) the constructor utomatically initializes a suitable random number generator using the order shown below:

  • /dev/random
  • /dev/urandom
  • lrand48
  • rand

It takes the first it finds from the list above.

Parameters:
request the requested engine or AUTO for auto determination.

Definition at line 262 of file rng.cc.

References YAPET::PWGEN::AUTO, YAPET::PWGEN::DEVRANDOM, YAPET::PWGEN::DEVURANDOM, YAPET::PWGEN::LRAND48, and YAPET::PWGEN::RAND.

RNG::RNG ( const RNG r  )  throw (PWGenException)
RNG::~RNG (  )  throw () [virtual]

Definition at line 326 of file rng.cc.

References YAPET::PWGEN::DEVRANDOM, YAPET::PWGEN::DEVURANDOM, fd, and rng_used.


Member Function Documentation

size_t RNG::_lrand48 ( size_t  ceil  )  throw () [private]

Definition at line 208 of file rng.cc.

References YAPET::PWGEN::LRAND48.

size_t RNG::_rand ( size_t  ceil  )  throw () [private]

Definition at line 227 of file rng.cc.

References YAPET::PWGEN::RAND.

void RNG::check_availability (  )  throw (PWGenException) [static, private]

Definition at line 72 of file rng.cc.

References rng_available.

Referenced by getAvailableRNGs().

Here is the caller graph for this function:

size_t RNG::devrandom ( size_t  ceil  )  throw (PWGenException) [private]

return a random number from either /dev/random or /dev/urandom, depending on which is used.

Parameters:
ceil the maximum value to return.
Returns:
a random number

Definition at line 161 of file rng.cc.

References YAPET::PWGEN::DEVRANDOM, and YAPET::PWGEN::DEVURANDOM.

int RNG::getAvailableRNGs (  )  [static]

Definition at line 92 of file rng.cc.

References check_availability(), and rng_available.

Referenced by PWGenDialog::PWGenDialog().

Here is the call graph for this function:

Here is the caller graph for this function:

size_t RNG::getRandomNumber ( size_t  ceil  )  throw (PWGenException)

Definition at line 337 of file rng.cc.

References YAPET::PWGEN::AUTO, YAPET::PWGEN::DEVRANDOM, YAPET::PWGEN::DEVURANDOM, YAPET::PWGEN::LRAND48, YAPET::PWGEN::NONE, and YAPET::PWGEN::RAND.

Referenced by operator()().

Here is the caller graph for this function:

RNGENGINE YAPET::PWGEN::RNG::getRNGEngineUsed (  )  const throw () [inline]

Definition at line 121 of file rng.h.

References rng_used.

Referenced by YAPET::PWGEN::PWGen::getRNGUsed().

Here is the caller graph for this function:

void RNG::init_rng ( RNGENGINE  request  )  throw (PWGenException) [private]

Initializes the given engine.

Expects check_availabilit() is already called.

Parameters:
request the engine requested.

Definition at line 105 of file rng.cc.

References YAPET::PWGEN::AUTO, YAPET::PWGEN::DEVRANDOM, YAPET::PWGEN::DEVURANDOM, YAPET::PWGEN::LRAND48, YAPET::PWGEN::NONE, and YAPET::PWGEN::RAND.

size_t YAPET::PWGEN::RNG::operator() ( size_t  ceil  )  throw (PWGenException) [inline]

Definition at line 125 of file rng.h.

References getRandomNumber().

Here is the call graph for this function:

const RNG & RNG::operator= ( const RNG r  )  throw ()

Member Data Documentation

int YAPET::PWGEN::RNG::fd [private]

File descriptor, used with /dev/[u]random.

Definition at line 78 of file rng.h.

Referenced by ~RNG().

int RNG::rng_available = 0 [static, private]

stores which rng are available.

Definition at line 100 of file rng.h.

Referenced by check_availability(), and getAvailableRNGs().

Indicates that whatever steps are need to initialize the rng, they have been taken.

Definition at line 86 of file rng.h.

stores which rng is used.

Definition at line 93 of file rng.h.

Referenced by getRNGEngineUsed(), and ~RNG().


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