Skip to content

Instantly share code, notes, and snippets.

@luismasuelli
Created May 25, 2017 17:52
Show Gist options
  • Save luismasuelli/420f1a300d8570034e4d01d555516737 to your computer and use it in GitHub Desktop.
Save luismasuelli/420f1a300d8570034e4d01d555516737 to your computer and use it in GitHub Desktop.
Dice rolling
Random.srand
class Integer
def d n
times.map{|_e| Random.rand(n) + 1}.inject 0, :+
end
private :d
def d2
d 2
end
def d4
d 4
end
def d6
d 6
end
def d8
d 8
end
def d10
d 10
end
def d12
d 12
end
def d20
d 20
end
def d100
d 100
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment