roll: Difference between revisions
Jump to navigation
Jump to search
Verisimilar (talk | contribs) m (Added to Dice Function category.) |
No edit summary |
||
Line 17: | Line 17: | ||
{{param|times|The number of times to roll the dice.}} | {{param|times|The number of times to roll the dice.}} | ||
{{param|sides|The number of sides the dice possess.}} | {{param|sides|The number of sides the dice possess.}} | ||
'''Note:''' | |||
The roll function does not keep track of the individual dice rolled. In other words their results are lost, just the total is kept. How to roll dice when individual dice matter is shown in the examples. | |||
|examples= | |examples= | ||
Line 37: | Line 41: | ||
}} | }} | ||
Throw multiple dice and sort and sum the result. Note that roll() doesnt help with this. You have to rol individual dice and keep track yourself. Gladly MapTool does help with loops and listkeeping functions. | |||
<source lang="mtmacro"> | |||
[h: diceTimes = 5] | |||
[h: diceSides = 6] | |||
[h: listOfRolls = ""] | |||
[h: sum = 0] | |||
[h, count(diceTimes), code: { | |||
[h: r = roll(1, diceSides)] | |||
[h: sum = sum+r] | |||
[h: listOfRolls = listAppend(listOfRolls, r)] | |||
}] | |||
You rolled [r: listSort(listOfRolls, "N-")] = [r: sum]. | |||
[[Category:Dice Function]] | [[Category:Dice Function]] |
Revision as of 22:25, 10 November 2011
roll() Function
Generates random numbers to emulate dice rolls. You may also think of this function as a method of generating a random number between
times
and times*sides
.Usage
roll(times, sides)
dice(times, sides)
d(times, sides)
Parameters
times
- The number of times to roll the dice.sides
- The number of sides the dice possess.
Note: The roll function does not keep track of the individual dice rolled. In other words their results are lost, just the total is kept. How to roll dice when individual dice matter is shown in the examples.
Examples
Roll a twenty-sided dice.
Returns a number than is between
[t: roll(1, 20)]
Returns a number that is between 1
and 20
.
Roll five ten-sided dice, using variables.
[h: DiceTimes = 5]
[h: DiceSides = 10]
[t: roll(DiceTimes, DiceSides)]
5
and 50
.See Also
For another method of rolling dice, see Dice Expressions.
Throw multiple dice and sort and sum the result. Note that roll() doesnt help with this. You have to rol individual dice and keep track yourself. Gladly MapTool does help with loops and listkeeping functions.
<source lang="mtmacro"> [h: diceTimes = 5] [h: diceSides = 6] [h: listOfRolls = ""] [h: sum = 0] [h, count(diceTimes), code: {
[h: r = roll(1, diceSides)] [h: sum = sum+r] [h: listOfRolls = listAppend(listOfRolls, r)]
}] You rolled [r: listSort(listOfRolls, "N-")] = [r: sum].