Random: Difference between revisions
Jump to navigation
Jump to search
imported>StDoodle mNo edit summary |
imported>PhilmASTErpLus m Clarified text |
||
(One intermediate revision by one other user not shown) | |||
Line 5: | Line 5: | ||
FunctionPage| | FunctionPage| | ||
name={{#var:name}}| | name={{#var:name}}| | ||
function1={{Function| | function1={{Function| | ||
Line 16: | Line 15: | ||
}}| | }}| | ||
function_description=Generates a random number, from a minimum of 0 to a maximum of | function_description=Generates a random number, from a minimum of 0 to a maximum of {{pspan|range}}-1. Note that this function aborts with an error if you attempt to supply 1 for {{pspan|range}} (not that a number between 0 and 0 is all that random).| | ||
Line 29: | Line 28: | ||
</syntaxhighlight>}}| | </syntaxhighlight>}}| | ||
}} | }} | ||
[[Category:Math and Numbers]] |
Latest revision as of 01:35, 3 July 2010
Function Syntax
- range is the number of unique numbers to choose from
Generates a random number, from a minimum of 0 to a maximum of range-1. 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) );