Skip to content

Instantly share code, notes, and snippets.

@Pagwin2
Created April 24, 2022 23:08
Show Gist options
  • Select an option

  • Save Pagwin2/2d2962289547d9c05ea6d3e351ba514f to your computer and use it in GitHub Desktop.

Select an option

Save Pagwin2/2d2962289547d9c05ea6d3e351ba514f to your computer and use it in GitHub Desktop.
a simple python file to simulate a St. Petersburg lottery
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