Random

From Kolmafia
Revision as of 05:06, 22 May 2010 by imported>Bale
Jump to navigation Jump to search

Function Syntax

int random(int range )

  • range is the number of unique numbers to choose from

Generates a random number, from a minimum of 0 to a maximum of 1 less than range. Note that this function aborts with an error if you attempt to supply 1 for range (not that a number between 0 and 0 is all that random).

Code Sample

Mimics the effects of rolling 2d6 (two standard 6-sided dice to you non-gamer-geeks).

int die1 = 1 + random(6);
int die2 = 1 + random(6);
print( "You rolled a " + die1 + " and a " + die2 + ", for a total of " + to_string(die1+die2) );