|
Utilities Package
Version Linux2023.0
|
For generating pseudorandom integer, real, character and string values. More...
#include <utilities.h>
Public Member Functions | |
| RandomGenerator () | |
Default constructor, based on seed obtained from a call to the time() function. More... | |
| RandomGenerator (int userSeedValue) | |
| Constructor based on a client-supplied seed. More... | |
| void | reset () |
Resets the random generator using a seed obtained by a call to the time() function. More... | |
| void | reset (int userSeedValue) |
| Resets the random generator using a seed supplied by the client. More... | |
| int | getNext (int n) |
| Gets a pseudorandom integer in the range [0,n). More... | |
| int | getNextInt (int n) |
| Same as getNext(int n) above, but with a more explicit name, for readability rather than for ease of use when programming "generically". More... | |
| int | getNext (int low, int high) |
| Gets a pseudorandom integer in the range [low,high]. More... | |
| int | getNextInt (int low, int high) |
| Same as getNext(int low, int high) above, but with a more explicit name, for readability rather than for ease of use when programming "generically". More... | |
| double | getNext (double x) |
| Gets a pseudorandom real (double) in the range [0,x). More... | |
| double | getNextDouble (double x) |
| Same as getNext(double x) above, but with a more explicit name, for readability rather than for ease of use when programming "generically". More... | |
| double | getNext (double low, double high) |
| Gets a pseudorandom real (double) value in the range [low,high). More... | |
| double | getNextDouble (double low, double high) |
| Same as getNext(double low, double high) above, but with a more explicit name, for readability rather than for ease of use when programming "generically". More... | |
| string | getNext (const string &s) |
| Gets a pseudorandom string based on the length and content of s. More... | |
| string | getNextString (const string &s) |
| Same as getNext(const string& s) above, but with a more explicit name, for readability rather than for ease of use when programming "generically". More... | |
| string | getNext (const string &first, const string &second) |
| Gets a random string in the "range" between the two strings first and second. More... | |
| string | getNextString (const string &first, const string &second) |
| Same as getNext(const string& first, const string& second) above, but with a more explicit name, for readability rather than for ease of use when programming "generically". More... | |
| string | getNextStringFromCharRange (int size, char firstChar, char lastChar) |
| Gets a pseudorandom string containing size characters from the character range [firstChar,secondChar]. More... | |
| string | getNextStringFromString (int size, const string &source) |
Gets a pseudorandom string containing size characters taken from the string s. More... | |
For generating pseudorandom integer, real, character and string values.
The RandomGenerator class can be used to generate pseudorandom values of the following types:
| Scobey::RandomGenerator::RandomGenerator | ( | ) |
Default constructor, based on seed obtained from a call to the time() function.
If a random generator constructed by this constructor is used, the sequence of random values will be different each time.
time() function. | Scobey::RandomGenerator::RandomGenerator | ( | int | userSeedValue | ) |
Constructor based on a client-supplied seed.
If a random generator constructed by this constructor is used, the userSeedValue used determines the sequence of random values obtained, and the same sequence of values can be obtained on a subsequent run by reusing the same userSeedValue. This same userSeedValue can be used to construct a new random generator object using this constructor, or to reset an already existing random generator object using the reset() method; either way, you get the same sequence of values as you did when that userSeedValue was employed previously.
| userSeedValue | A seed value supplied by the client. |
| void Scobey::RandomGenerator::reset | ( | ) |
Resets the random generator using a seed obtained by a call to the time() function.
| void Scobey::RandomGenerator::reset | ( | int | userSeedValue | ) |
Resets the random generator using a seed supplied by the client.
| int Scobey::RandomGenerator::getNext | ( | int | n | ) |
Gets a pseudorandom integer in the range [0,n).
| n | A positive integer value. |
| int Scobey::RandomGenerator::getNextInt | ( | int | n | ) |
Same as getNext(int n) above, but with a more explicit name, for readability rather than for ease of use when programming "generically".
| int Scobey::RandomGenerator::getNext | ( | int | low, |
| int | high | ||
| ) |
Gets a pseudorandom integer in the range [low,high].
| low | A positive integer value <= the value of high. |
| high | A positive integer value >= the value of low. |
| int Scobey::RandomGenerator::getNextInt | ( | int | low, |
| int | high | ||
| ) |
Same as getNext(int low, int high) above, but with a more explicit name, for readability rather than for ease of use when programming "generically".
| double Scobey::RandomGenerator::getNext | ( | double | x | ) |
Gets a pseudorandom real (double) in the range [0,x).
| x | A positive real (double) number. |
| double Scobey::RandomGenerator::getNextDouble | ( | double | x | ) |
Same as getNext(double x) above, but with a more explicit name, for readability rather than for ease of use when programming "generically".
| double Scobey::RandomGenerator::getNext | ( | double | low, |
| double | high | ||
| ) |
Gets a pseudorandom real (double) value in the range [low,high).
| low | A positive real (double) value < the value of high. |
| high | A positive real (double) value > the value of low. |
| double Scobey::RandomGenerator::getNextDouble | ( | double | low, |
| double | high | ||
| ) |
Same as getNext(double low, double high) above, but with a more explicit name, for readability rather than for ease of use when programming "generically".
| string Scobey::RandomGenerator::getNext | ( | const string & | s | ) |
Gets a pseudorandom string based on the length and content of s.
| s | Any string of characters. |
| string Scobey::RandomGenerator::getNextString | ( | const string & | s | ) |
Same as getNext(const string& s) above, but with a more explicit name, for readability rather than for ease of use when programming "generically".
| string Scobey::RandomGenerator::getNext | ( | const string & | first, |
| const string & | second | ||
| ) |
Gets a random string in the "range" between the two strings first and second.
| first | The "lower bound" of a "string range" from which the pseudorandom string object will be chosen. |
| second | The "upper bound" of a "string range" from which the pseudorandom string object will be chosen. |
r satisfying the following three conditions is returned:| string Scobey::RandomGenerator::getNextString | ( | const string & | first, |
| const string & | second | ||
| ) |
Same as getNext(const string& first, const string& second) above, but with a more explicit name, for readability rather than for ease of use when programming "generically".
| string Scobey::RandomGenerator::getNextStringFromCharRange | ( | int | size, |
| char | firstChar, | ||
| char | lastChar | ||
| ) |
Gets a pseudorandom string containing size characters from the character range [firstChar,secondChar].
| size | The size of the string to be returned. |
| firstChar | The lower bound of the character range from which the characters for the returned string will be taken. |
| lastChar | The upper bound of the character range from which the characters for the returned string will be taken. |
| string Scobey::RandomGenerator::getNextStringFromString | ( | int | size, |
| const string & | source | ||
| ) |
Gets a pseudorandom string containing size characters taken from the string s.
| size | The size of the string to be returned. |
| source | The string from which the characters for the returned string will be taken. |
1.8.17