Created
September 3, 2012 23:35
-
-
Save mahiuchun/3614851 to your computer and use it in GitHub Desktop.
HW0 Problem2 Simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import os | |
cnum = 1000000 | |
total = 0 | |
n = 6 | |
random.seed(os.urandom(1024)) | |
for i in range(cnum): | |
money = 0 | |
alice = random.choice(range(1, n+1)) | |
bob = 0 | |
while bob < alice: | |
bob = random.choice(range(1, n+1)) | |
money = money + 1 | |
total = total + money | |
print total / float(cnum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment