randomint Class Reference

#include <randomint.hpp>

List of all members.

Public Member Functions

 randomint (int low, int high)
int operator() () const
 Generate the next random number generator.


Detailed Description

Generate random numbers. The standard rand() function returns random integers in the range [0, RAND_MAX]. The goal is to obtain uniformly-distributed numbers in the range [low, high]. To achieve properly distributed numbers, check whether the value rand() returns is in the range [0, (high-low+1)*k] where k is the largest integer such that (high-low+1)*k < RAND_MAX. If the random number is out of range, discard it and get another one. Then take the value mod (high-low+1) and add low to get the random result.

Definition at line 17 of file randomint.hpp.


Constructor & Destructor Documentation

randomint::randomint ( int  low,
int  high 
) [inline]

Construct a random-number generator to produce numbers in the range [low, high]. If low > high the values are reversed. This class uses the std::rand() function, so you call std::srand() to change the seed.

Definition at line 33 of file randomint.hpp.


The documentation for this class was generated from the following file:
Generated on Sun Nov 30 09:53:23 2008 for Exploring C++ - Final Forms of Key Examples by  doxygen 1.5.3