Skip to content

Instantly share code, notes, and snippets.

@sahands
Last active December 19, 2015 15:38
Show Gist options
  • Save sahands/5977365 to your computer and use it in GitHub Desktop.
Save sahands/5977365 to your computer and use it in GitHub Desktop.
Fair Coin from Unfair Coin - Groupon Interview Question
import random
def bernoulli_process(p):
if p > 1.0 or p < 0.0:
raise ValueError("p should be between 0.0 and 1.0.")
while True:
yield random.random() < p
def von_neumann_extractor(process):
while True:
x, y = process.next(), process.next()
if x != y:
yield x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment