#!/usr/bin/ruby
module Game
class Die
class << self
def roll num, val, drop = 0
sto = Array.new num
0.upto(num - 1){ |a| sto[a] = rand(1 .. val) }
sum = 0
unless drop > 0
sto.each { |b| sum += b }
else
sto.sort!
0.upto(num - 1 - drop) { |b| sum += b }
end
sum
end
end
end
end
Name:
Anonymous2012-01-11 8:21
Lots of pig disgusting untyped code here.
using System;
public class Die
{
public uint sides
{
get; protected set;
}
public Die(uint nSides = 6)
{
this.sides = nSides;
}
public int Roll()
{
Random r = new Random();
return r.Next((int)sides+1);
}
}