First app troubles

hi, since I just started learning Ruby I’m still having troubles to make
things work properly. So, here’s the case. I decided to write an app
that will emulate rolling diced, simple as that and just print result.
I’m working with NetBeans and Ruby plugins and here’s my syntax.

“def dice_roller()
puts “What dice do you want to roll?”
dice = gets.chomp
if dice == “d4”
dice_d4 = Random.new
puts “Your score is #{dice_d4}”
end
if dice == “d6”
dice_d6 = Random.new
puts “Your score is #{dice_d6}”
end
if dice == “d8”
dice_d8 = Random.new
puts “Your score is #{dice_d8}”
end
if dice == “d10”
dice_d10 = Random.new
puts “Your score is #{dice_d10}”
end
if dice == “d12”
dice_d12 = Random.new
puts “Your score is #{dice_d12}”
end
if dice == “d20”
dice_d20 = Random.new
puts “Your score is #{dice_d20}”
end
end”

Would you, please, tell me what is wrong? And if at least I’m heading in
the right direction?

You need to use the rand method on the Random class such as
Random.new.rand(number_of_sides).

here’s your code refactored a bit just to give you some new ideas:

def dice_roller
puts “What dice do you want to roll?”
dice_sides = gets.chomp.gsub(/[^0-9]/, “”).to_i
puts “rolled a d#{dice_sides}, got a #{Random.new.rand(dice_sides)}”
end

dice_roller

Okay, thanks. I think I sorted it out thanks to you. Now got to find out
what is wrong with NetBeans since it not too cooperative. :]

Cheers for help

If you have an array and are seeking a randomized sample from that array
the method you are looking for is Array#sample.