Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Polyhedral Dice

DZone's Guide to

Polyhedral Dice

·
Free Resource
// Allows a user to determine how many dice are being rolled and how many sides the dice have then totals the results.  This was designed for my personal use with Dungeons and Dragons since I do not own any physical dice.  Feel free to use this code and improve upon it.  Any suggestions are more than welcome.  I am a Ruby novice.


    puts "How many dice are you rolling?  "
    dice = gets.chomp
    puts "How many sides does each die have?  "
    sides = gets.chomp
    x = 0
    y = dice.to_i
    while x < y
            result = result.to_i + rand(sides.to_i) + 1
            x = x + 1
    end
    puts "The number you rolled is " + result.to_s
    gets
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}