From: Josh Cheek Date: 2009-09-26T05:05:34+09:00 Subject: Re: Roulette & rand --000e0cd254365b2a1004746c78a1 Content-Type: text/plain; charset=ISO-8859-1 On Fri, Sep 25, 2009 at 7:26 AM, 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/. > > Hi, it is giving me the output that I would expect, here is a image showing how I calculated it, and I ran the program 3 times with results very similar to what I calculated they should be. http://img132.imageshack.us/img132/8939/roulette.png --000e0cd254365b2a1004746c78a1--