Skip to content

Instantly share code, notes, and snippets.

@gngdb
Created April 9, 2020 21:48
Show Gist options
  • Select an option

  • Save gngdb/f4bb42c640cf05e009a82f841865a254 to your computer and use it in GitHub Desktop.

Select an option

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