diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-11-17 15:42:27 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-11-17 15:42:27 +0100 |
| commit | fb80ac50825c7ca1fa063d3493175b7b27adbdb1 (patch) | |
| tree | 4d84895d45ca2c177ddefe11164575bf6762b3ca /labb5/lib/StanfordCPPLib/random.h | |
| parent | 4065799f7080260f507a5e3ea8c2d8375e735166 (diff) | |
| download | tddd86-fb80ac50825c7ca1fa063d3493175b7b27adbdb1.tar.gz | |
add given code
Diffstat (limited to 'labb5/lib/StanfordCPPLib/random.h')
| -rwxr-xr-x | labb5/lib/StanfordCPPLib/random.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/labb5/lib/StanfordCPPLib/random.h b/labb5/lib/StanfordCPPLib/random.h new file mode 100755 index 0000000..3286f8f --- /dev/null +++ b/labb5/lib/StanfordCPPLib/random.h @@ -0,0 +1,58 @@ +/* + * File: random.h + * -------------- + * This file exports functions for generating pseudorandom numbers. + */ + +#ifndef _random_h +#define _random_h + +/* + * Function: randomInteger + * Usage: int n = randomInteger(low, high); + * ---------------------------------------- + * Returns a random integer in the range <code>low</code> to + * <code>high</code>, inclusive. + */ + +int randomInteger(int low, int high); + +/* + * Function: randomReal + * Usage: double d = randomReal(low, high); + * ---------------------------------------- + * Returns a random real number in the half-open interval + * [<code>low</code> .. <code>high</code>). A half-open + * interval includes the first endpoint but not the second, which + * means that the result is always greater than or equal to + * <code>low</code> but strictly less than <code>high</code>. + */ + +double randomReal(double low, double high); + +/* + * Function: randomChance + * Usage: if (randomChance(p)) ... + * ------------------------------- + * Returns <code>true</code> with the probability indicated by <code>p</code>. + * The argument <code>p</code> must be a floating-point number between + * 0 (never) and 1 (always). For example, calling + * <code>randomChance(.30)</code> returns <code>true</code> 30 percent + * of the time. + */ + +bool randomChance(double p); + +/* + * Function: setRandomSeed + * Usage: setRandomSeed(seed); + * --------------------------- + * Sets the internal random number seed to the specified value. You + * can use this function to set a specific starting point for the + * pseudorandom sequence or to ensure that program behavior is + * repeatable during the debugging phase. + */ + +void setRandomSeed(int seed); + +#endif |
