Skip to content

Instantly share code, notes, and snippets.

@gngdb
Created April 9, 2020 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gngdb/f4bb42c640cf05e009a82f841865a254 to your computer and use it in GitHub Desktop.
Save gngdb/f4bb42c640cf05e009a82f841865a254 to your computer and use it in GitHub Desktop.
Pure Python Gumbel Dice
import dice
print(dice.roll(12))
import dice
print(dice.roll(20))
import dice
print(dice.roll(6))
import math
from random import random
def gumbel(eps=1e-6):
U = random()
return -math.log(-math.log(U+eps)+eps)
def roll(sides):
G = [gumbel() for i in range(sides)]
return [i for g,i in zip(G, range(sides)) if g == max(G)][0]+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment