class FTLTools::Dice
Provides basic random number generation.
Public Instance Methods
roll_1()
click to toggle source
Roll of 1d6.
# File lib/ftl_tools/dice.rb, line 9 def roll_1 roller('d6') end
roll_2()
click to toggle source
Roll of 2d6.
# File lib/ftl_tools/dice.rb, line 14 def roll_2 roller('2d6') end
roll_66()
click to toggle source
Roll of 1d6 for the first digit, and 1d6 for the second digit.
# File lib/ftl_tools/dice.rb, line 19 def roll_66 roll = roll_1.to_s + roll_1.to_s roll.to_i end
roll_several(num = 1, dice = 2)
click to toggle source
Provide a number of rolls of a similar type.
# File lib/ftl_tools/dice.rb, line 25 def roll_several(num = 1, dice = 2) rolls = [] num.times do case dice when 1 rolls << roll_1 when 2 rolls << roll_2 when 66 rolls << roll_66 end end rolls end
roller(roll_string)
click to toggle source
Create the roller
# File lib/ftl_tools/dice.rb, line 41 def roller(roll_string) if roll_string.index(/[\+\-]/).nil? modifier = 0 else modi = roll_string.index(/[\+\-]/) modifier = roll_string[modi..-1].to_i end d_index = roll_string.index('d') if d_index == 0 dice_num = 1 else dice_num = roll_string[0...d_index].to_i end dice_type = roll_string[d_index + 1..-1].to_i roll = modifier dice_num.times { roll += rand(1..dice_type) } return roll end