/* * File: random.h * -------------- * This file exports functions for generating pseudorandom numbers. */ /*************************************************************************/ /* Stanford Portable Library */ /* Copyright (c) 2014 by Eric Roberts <eroberts@cs.stanford.edu> */ /* */ /* This program is free software: you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation, either version 3 of the License, or */ /* (at your option) any later version. */ /* */ /* This program is distributed in the hope that it will be useful, */ /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ /* GNU General Public License for more details. */ /* */ /* You should have received a copy of the GNU General Public License */ /* along with this program. If not, see <http://www.gnu.org/licenses/>. */ /*************************************************************************/ #ifndef _random_h #define _random_h/* * Function: randomInteger * Usage: int n = randomInteger(low, high); * ---------------------------------------- * Returns a random integer in the range low to high, 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 [low, high). A * half-open interval includes the first endpoint but not the second, which * means that the result is always greater than or equal to low but * strictly less than high. */ double randomReal(double low, double high);/* * Function: randomChance * Usage: if (randomChance(p)) ... * ------------------------------- * Returns true with the probability indicated by p. The argument p must * be a floating-point number between 0 (never) and 1 (always). For * example, calling randomChance(.30) returns true 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