I made the following program:
class PowerBall
def jogo
brancas = Array.new
50.times{brancas << false}
brancasSorteadas = Array.new
5.times{brancasSorteadas << 0}
for x in brancasSorteadas
j = rand(48) + 1
if brancas[j-1] == false
brancas[j-1] = true
brancasSorteadas[x] = j
else
x -= 1
end
end
for x in brancasSorteadas
puts "A bola branca eh: #{brancasSorteadas[x]}"
end
puts "A bola vermelha eh: #{rand(42)}"
end
end
a = PowerBall.new
a.jogo
The goal is to remove five white balls from a bucket of 49 balls without repetition and draw a red ball from a bucket of 42 balls and can repeat some drawing from the white bucket.
Only the result is giving the following:
A bola branca eh:
A bola branca eh:38
A bola branca eh:38
A bola branca eh:38
A bola branca eh:38
A bola vermelha eh:numero aleatorio
Varying the number that repeats each time the program is called. Does anyone know where the error is?