Skip to content

Instantly share code, notes, and snippets.

@vyder
Created February 2, 2014 21:08
Show Gist options
  • Select an option

  • Save vyder/8775000 to your computer and use it in GitHub Desktop.

Select an option

Save vyder/8775000 to your computer and use it in GitHub Desktop.
Any-sided multiple dice, multiple rolls
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