# Roulette Algorithm Probability Loop

109 views (last 30 days)
Mark on 4 Apr 2013
Commented: Gaven Henry on 22 Jun 2021
I am making a program that will run a roulette style program 1000000 times. The program should give me an output with my average winnings per trip to the casino. I am starting with 315 dollars and the conditions for betting are: if I lose i will double my bet and play again. If I win, I will start my bid back at my first initial bid amount (5 dollars) I have created a random number generator and an equation to determine my probability, I have having trouble with the loop. while numbers are generating I am trying to have the program do the bidding for me and my results are less than successful. Any ideas? I realize now that one of my equations in the loop is incorrect, I am just concerned with getting the loop to work at the moment. Thanks!
A = 315 %starting amount of money
initial = 5 %Initial bet amount
WIN = 335 %Condition for a win
LOSE = 0 %Condition for loss
profit = 0
g = 0 %counter for random numbers when multiplied by %probability
N = ((log(A+5)-log(5))/log(2)) %Number of bets
Pwinner = (1 - (1/2^N))^4 %Probability of a win
a = initial * (2^N -1) %bid condition for a loss
Gwinner = (1 - (10/19)^N)^4 %probability of win with green slots
%Allow Green Slots?
x = input('Do you want to allow for the green slots (0=No, 1=Yes)? ');
if x == 0;
r = randi([1,36],[1000000 ,1]);
round(r)
else
r = randi([1,38],[1000000 ,1]);
round(r)
end
fprintf('Please wait while computer simulates game 1000000 times');
%Solution while A < WIN && A > LOSE
g = Pwinner .* r;
round(g);
if g > 18;
A = A - initial
profit = (1/2^N) * A
else
fprintf('this isnt working')
end
end
Jan on 5 Apr 2013
Thanks for answering my questions, Mark. Does the opriginal code contain an empty line after each line of code? You can follow the "? Help" link to learn, how to improve the readability of your code. And making the reading as easy as possible is a good strategy in a forum.

Mark on 5 Apr 2013
I got it! Here is my code!!!
%Starting Over
%Algorithm #3
%Simulating Roulette
fprintf('\t\t\t\tSimulating Roulette\n\n')
%Constants and Variables
A = 315; %starting amount of money
initial = 5; %Initial bet amount
WIN = 335; %Condition for a win
LOSE = 0; %Condition for loss
betamount = initial; %set bet amount to 5
g = 1; %counter for random numbers
profit = 0; %profit counter
y = 1000000; %amount of games we wil play
N = ((log(A+5)-log(5))/log(2)); %Number of bets
Pwinner = (1 - (1/2^N))^4; %Probability of a win
a = initial * (2^N -1); %bid condition for a loss
Gwinner = (1 - (10/19)^N)^4; %probability of win with green slots
%Allow Green Slots?
x = input('Do you want to allow for the green slots (0=No, 1=Yes)? ');
%Generate random numbers that the game will use
if x == 0;
r = randi([1,36],[20000000 ,1]);
round(r);
else
r = randi([1,38],[20000000 ,1]);
round(r);
end
fprintf('Please wait while computer simulates game 1000000 times');
%Solution
for i = 1:y %Number of times the loop will run
A = 315; %Reset amount of money to 315
%every game
while A < WIN && A > LOSE %Condition for loop
if betamount > A %Can't over bid
betamount = A;
end
A = A - betamount; %Subtract bet from total money
if r(g)<= 18 %Condition for win/loss
A = A + (betamount *2); %Recalculates total money
betamount = initial; %Resets bet to 5
else
betamount = betamount * 2; %If I lose double my bet
end
g = g + 1; %used with r(g) to isolate integers
end
profit = profit + A; %counts my total profits
end
if x == 0 %Loop to print answer an a clear screen
clc
fprintf('\t\t\t\tSimulating Roulette\n\n');
fprintf('With only 18 red and 18 black (no green), you won 93.90 percent\n of the time you went to the casino\n\n')
fprintf('Your average winnings were %.2f per trip to the casino', (profit/y-315)) % profit/y-315 = profit per trip to the casino
else
clc
fprintf('\t\t\t\tSimulating Roulette\n\n');
fprintf('With 18 red, 18 black, and 2 green slots, you won 91.74 percent\n of the time you went to the casino\n\n')
fprintf('Your average winnings were %.2f per trip to the casino', (profit/y-315)) % profit/y-315 = profit per trip to the casino
end

ChristianW on 4 Apr 2013
To summarize the strategie: You allways lose all your money. This is for 37 slots, only one zero slot.
bet0 = 5; % initial bet amount
bank0 = 315; % initial bankroll
display = 1;
bet = bet0;
bank = bank0;
n = 0;
while 1
n = n+1;
r = randi([0 36]); % Roulette Wheel
win = 18 < r;
if win
bank(n+1) = bank(n)+bet(n);
bet(n+1) = bet0;
else % lost
bank(n+1) = bank(n)-bet(n);
bet(n+1) = 2*bet(n);
if bet(n+1) > bank(n+1)
if display, disp_state(win,bank(n:n+1),bet(n:n+1)); end
break
end
end
if display, disp_state(win,bank(n:n+1),bet(n:n+1)); end
end
plot(bet,'k'), hold on, plot(bank,'r')
-----
function disp_state(win,bank,bet)
wonstr = {'lost','won'};
fprintf('--- %4s\n',wonstr{win+1})
fprintf('Bank [\$] %6d -> %4d\n',bank)
fprintf('Bet [\$] %6d -> %4d\n',bet)
fprintf('\n')

Kent Peacock on 4 Sep 2020
Guys, if you really want to know how the algorithms for roulette in online casinos are correctly composed, you need to study this process in more detail.
Gaven Henry on 22 Jun 2021
I'm going to explain you how the casino account information can be found. Since many people are looking for it, many individuals do not know where to find it easily. That too, I know. Clearly read the fashionable parimatch win . I'm glad this is the data I've found here and I know that it's already fine, decent casino. You read it carefully, I propose. I hope I'll help in this case.