Skip to content

Instantly share code, notes, and snippets.

@gennad
Created May 27, 2011 09:02
Show Gist options
  • Save gennad/994894 to your computer and use it in GitHub Desktop.
Save gennad/994894 to your computer and use it in GitHub Desktop.
rand5 to 7
import random
def rand5():
seq = [0,1,2,3,4,5]
return random.choice(seq)
def rand7():
i = 5 * (rand5() - 1) + rand5()
while i > 21:
i = 5 * (rand5() - 1) + rand5()
return i % 7 + 1
print rand7()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment