Skip to content

Instantly share code, notes, and snippets.

@jujum4n
Created September 29, 2015 21:37
Show Gist options
  • Select an option

  • Save jujum4n/ecb8f671ea8f89122791 to your computer and use it in GitHub Desktop.

Select an option

Save jujum4n/ecb8f671ea8f89122791 to your computer and use it in GitHub Desktop.
Simple Roulette Simulator/Martingale Simulator I programmed
import random
#Global Variables for running simulations
T = 1000
B = 2
R = 0
#Definition of the Colors and their corresponding Numbers
RED = [1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36]
BLACK = [2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35]
GREEN = [0]
def color(n):
if n in RED:
return 1
if n in BLACK:
return 2
if n in GREEN:
return 3
def roll(n):
W = 0
for i in xrange(1, n):
R = random.randrange(37)
C = color(R)
if C == B:
W += 1
if C != B:
continue
return W
def roll(n, betvalue, P):
W = False
for i in xrange(1, n):
R = random.randrange(37)
C = color(R)
if C == B:
W = True
P += (betvalue*2)
if C != B:
P -= betvalue
W = False
continue
return P, W
#Simulates Odds of Roulette Program ~48.4-48.6 win red/black
def simulate():
rollist = []
for i in xrange(1, T):
rollist.append(roll(T))
print sum(rollist)/T
return 1
#Simulates martingale betting, when losing you double your bet until your bet is larger than your running profit
#
def martingale():
P = 100
WIN = False
betincrements = 5
while P > 0 or P >= 200:
print 'Profit: ' + str(P) + ' Bet increment: ' + str(betincrements)
P, WIN = roll(2, betincrements, P)
if not WIN:
print 'Lost'
if ((betincrements*2) < P ):
betincrements = betincrements*2
else:
print 'You lost all your money'
return
if WIN:
print 'Won'
betincrements = 5
if (P >= 400):
print 'You doubled your money'
return
return
martingale()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment