Skip to content

Instantly share code, notes, and snippets.

@JRiggles
Created January 21, 2020 20:20
Show Gist options
  • Save JRiggles/ac3834241afbeb979055a8299a3d7d51 to your computer and use it in GitHub Desktop.
Save JRiggles/ac3834241afbeb979055a8299a3d7d51 to your computer and use it in GitHub Desktop.
Roll N dice with X sides (NdX) and get the results
def roll (n,d)
arr = []
n.times do
arr.push(rand(1..d))
end
puts "Min: #{n}"
puts "Max: #{n * d}"
puts "Expected: #{(n + n * d) / 2}" # The Expexted roll value is rounded down
puts "Total: #{arr.sum}"
puts "Rolls: #{arr}"
end
# Example:
roll(3,8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment