Roulette Algorithm Probability Loop
103 views (last 30 days)
Show older comments
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
3 Comments
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.
Accepted Answer
More Answers (2)
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')
0 Comments
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.
1 Comment
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!