Main
Using random numbers

This structure (public class) RandNr uses original implementation of Mersenne Twister algorithm (32 bit version) for making pseudo random numbers from random seed, and for organizing that numbers. Generator can be initialized by seed or by array.


Download sources and compiled library on Windows XP, MinGW: rand.zip (size: 7.5 KB, last modified: 2006/11/20).

function
description
RandNr :: RandNr(); Default constructor of RandNr object, initialize seed by standard time( 0 ) function.
void RandNr :: setSeed(); Initialize seed (not array) by standard time( 0 ) function.
void RandNr :: setSeed( uint addToseed ); Add to existing seed new value and set it again.
void RandNr :: newArray( uint size ); Create space for initializing array, this must be run before setArray method.
void RandNr :: setArray(); Initialize in array mode, array should contains random numbers (as random as possible), in all cases first element of initializing array is filled similarly as in single seed mode (by time( 0 ) function).
uint RandNr :: randInt( uint nr ); Output pseudo random number (integer) [ 0, nr ).
double RandNr :: randDouble( double nrD ); Output pseudo random number (double) [ 0, nrD ].
int RandNr :: randIntFromTo( int from, int to ); Output pseudo random number (integer) [ from, to ].
int RandNr :: randDoubleFromTo( double from, double to ); Output pseudo random number (double) [ from, to ].
bool RandNr :: probability( double pr ); Output true for some percentage of probability, or else is false (pr is double type number, pr >= 1.00 means 100%, pr <= 0 means 0%).


An example of using RandNr: example.cpp


Hosted by www.Geocities.ws

1