Created
January 21, 2020 20:20
-
-
Save JRiggles/ac3834241afbeb979055a8299a3d7d51 to your computer and use it in GitHub Desktop.
Roll N dice with X sides (NdX) and get the results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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