Created
April 24, 2022 23:08
-
-
Save Pagwin2/2d2962289547d9c05ea6d3e351ba514f to your computer and use it in GitHub Desktop.
a simple python file to simulate a St. Petersburg lottery
This file contains hidden or 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 math | |
| import random | |
| #number of games you want to simulate | |
| SAMPLE_SIZE = 10000000 | |
| x = [2**-math.floor(math.log2(random.random())) for i in range(SAMPLE_SIZE)] | |
| #output the average reward across the games | |
| print(sum(x)/len(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment