How do I write a Roulette Code?
Show older comments
Hi,
I want to write a code for a project where I am simulating a game of Roulette. I am having trouble writing a clean and easy code. I want to wrtie something where I play ~100 games consistently betting on Red (since you either bet on red or black)
I bet $1 on red every time and then see how much money I make from that (# of times its red out of ~ 100). So if I won I’d get +$1 and if I lose -$1 since it’s a 2:1 betting odds
Then I bet on a certain number (1-37) and I chose to consistently bet on #34. I play ~1000 games of that and see how much money I make (how many times it hits 34 when its 1-37). Every time the simulation hits the #34 I win $37 dollars since it’s a 37:1 odds.
I want to see how much money I make from the two simulations and decide which one is better (more money I win) depending on how many games I play
3 Comments
Walter Roberson
on 16 Apr 2019
You need to decide whether you are using American Roulette or European Roulette. The main difference is whether there is a 00 as well as a 0.
Payoff for getting the number right are apparently normally 35:1 not 37:1 . That makes a notable difference over the long run.
Roulette always has a "house edge", because the 0 (and possibly 00) are not red or black, not even or odd.
Tommy Agase
on 16 Apr 2019
Walter Roberson
on 16 Apr 2019
Let 38 be used for 0 and 39 be used for 00. Then
winnings = sum(randi(39, 1, 100) == 34) * 35
Answers (1)
Rik
on 16 Apr 2019
n_games=100;
your_number_pick=34;
Red=[1:2:9 12:2:18 19:2:27 30:2:36];
Black=[2:2:10 11:2:17 20:2:28 29:2:35];
roulette_result=randi(37,n_games,1);
isRed=ismember(roulette_result,Red);
isBlack=ismember(roulette_result,Black);
%bet on a number:
win=sum(roulette_result==your_number_pick);
expected_result__number=35*win-n_games;
%bet on a color:
win=sum(isRed);
expected_result__color=2*win-n_games;
fprintf(['expected results after %d games:\n',...
'%d for betting on 34\n%d for betting on red\n'],...
n_games,expected_result__number,expected_result__color)
Categories
Find more on Strategy & Logic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!