From: Paul Smith Date: 2009-09-25T22:10:19+09:00 Subject: Re: Roulette & rand On Fri, Sep 25, 2009 at 1:26 PM, Semih Ozkoseoglu wrote: > Hi again, > > I stumbled upon another interesting problem while I was playing with the > code that I mentioned above. > > After the simple roulette code sorted (thanks to everyone who has > responded) I tried to write a code where the bet was decided by another > random roll. Suddenly the code started to loose twice it was loosing > before. > > Now correct me if I'm wrong but shouldn't I always loose around 1/37 of > the time; no matter how I decide to bet on what color? > > I don't know if there is something wrong with my code or with my logic > and I welcome any suggestions. Again I'm sure its not the most important > problem but I'm just curious  why this might be happening. > > Thanks for reading and here is the code that I put together so far (i > tried to compare only betting red to betting randomly) > > > 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] >  number_02 = rand(37) >  color_02 = colors[number_02] > >  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/. > > 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)] maybe? -- Paul Smith http://www.nomadicfun.co.uk paul@pollyandpaul.co.uk