From: Semih Ozkoseoglu Date: 2009-09-27T09:15:19+09:00 Subject: Re: Roulette & rand Excuse my ignorance, After running the above code a few times I realized that the bet_rand and bet_red was always EXACTLY the same. So I realized that there was something wrong with the code. bet_rand somehow behaves exactly the same way as bet_red. I don't know whats wrong with it but it doesn't matter. > One problem that I can see is that you're allowing your random betting > strategy to pick 0, rather than red or black, which I don't think is > your intention. > > Change > >> number_02 = rand(37) >> color_02 = colors[number_02] > > to > > color_02 = [:red, :black][rand(2)] Here is the fixed code with Paul's suggestion colors = {} [2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35].each do |i| colors[i] = :black end [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36].each do |i| colors[i] = :red end colors[0] = :zero bet_rand = 0 bet_red = 0 puts 'How many rolls to simulate' number_of_rolls = gets.chomp.to_i number_of_rolls.times do number_01 = rand(37) color_01 = colors[number_01] color_02 = [:red, :black][rand(2)] if color_01 == :red bet_red += 1 else bet_red -= 1 end if color_02 == color_01 bet_rand += 1 else bet_rand -= 1 end end puts bet_rand puts bet_red -- Posted via http://www.ruby-forum.com/.