SECRandom Class
class SECRandom
SECRandom is a utility class for the generation of random numbers.
Defined in: SECRAND.H
Comments
An instance of SECRandom is initialized with an integer seed value from which random numbers are derived. If a seed of 0 is provided, a seed based on the current system time will be used.
SECRandom can provide a random value within a range by specifying an upper and lower bound for the range. SECRandom can also generate a skewed random result based on an array of weights specified by the user.
Each entry of the weighted array specifies an unsigned integer value (the weight) of what probability a random number will be generated for the entry. A higher number skews the probability that a random number will be generated for that position. Thus for a weighted array of 4 weights with the following layout:
PositionWeight
01
17
20
32
There is a 10 percent chance that a random number 0 will be generated, a 70 percent chance that a random number of 1 will be generated, no chance for a number of 2 being generated, and a 20 percent chance that a value of 3 will be generated if the user calls GetRandomWeighted.
Class Members
Creation/Initialization
SECRandom(unsigned int nSeed=0)
Constructs and seeds an SECRandom object.
BOOL InitWeights(unsigned int)
Initializes an empty weight array.
Attributes
BOOL AddWeight(unsigned int, unsigned int)
Add an individual weight to an existing weight array.
unsigned int GetSeed()
Retrieves the current seed value.
BOOL SetLBound(unsigned int)
Sets the lower bound of the range.
unsigned int GetLBound()
Retrieves the current lower bound of the range.
BOOL SetUBound(unsigned int)
Sets the upper bound of the range.
unsigned int GetUBound()
Retrieves the current upper bound of the range.
BOOL SetBounds(unsigned int, unsigned int)
Sets the upper and lower bounds of the range.
Operations
unsigned int GetRandom()
Returns a random value; no range is used in the calculation.
unsigned int GetRandomWeighted()
Returns a weighted random value based on the current weight array.
unsigned int GetRange()
Returns a random value within the current range.
unsigned int GetRange(unsigned int nMin, unsigned int nMax)
Returns a random value within the current range.
void SetMultiplier()
Sets the multiplier.
Protected data members
unsigned int m_nMin
Minimum value.
unsigned int m_nMax
Maximum value.
unsigned int m_nSeed
Seed used for Knuth operations.
double m_dMultiplier
Bounds multiplier
unsigned int m_nWeights
Number of weight values
unsigned int* m_pWeights
Pointer to weight array itself.