All pastes #364459 Raw Edit

Miscellany

public text v1 · immutable
#364459 ·published 2007-02-20 04:53 UTC
rendered paste body
#!/usr/bin/ruby

class Die
        def initialize(sides)
                @sides = sides
        end

        def roll()
                return (rand() * @sides).floor + 1
        end
end

class Roller<Array
        def roll()
                index = 0
                retVal = Array.new()
                while index < self.size()
                        retVal = retVal + [self[index].roll()]
                        index = index + 1
                end

                return retVal;
        end
end

srand()

puts 'Please enter sides for each die to be rolled to be seperated by a comma ($
requestedSides = gets.split(',');

puts 'how many times should we repeat these rolls: '
repeatCount = gets.to_i()

dice = Array.new()
index = 0;
while index < requestedSides.size()
        dice = dice + [ Die.new(requestedSides[index].to_i()) ]
        index = index + 1
end
roller = Roller.new(dice)

index = 0
while index < repeatCount
        rolls = roller.roll()
        puts 'rolls: '
        puts rolls
        puts ''
        index = index + 1
end