Created
February 2, 2014 21:08
-
-
Save vyder/8775000 to your computer and use it in GitHub Desktop.
Any-sided multiple dice, multiple rolls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Dice | |
| def self.roll( dice = [ "1d6" ], rolls = 1 ) | |
| output = "---\n" | |
| rolls.times do |roll| | |
| outcome = [] | |
| dice.each do |die| | |
| number_of_dice = die.split('d')[0].to_i | |
| sides = die.split('d')[1].to_i | |
| number_of_dice.times { outcome << (rand(sides) + 1) } | |
| end | |
| output += "Roll \##{roll}: " + outcome.join(" ") + "\n" | |
| end | |
| output += "---\n" | |
| return output | |
| end | |
| end | |
| puts Dice.roll(["2d6"], 3) | |
| puts Dice.roll(["2d6", "3d4"], 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment