Created
May 27, 2011 09:02
-
-
Save gennad/994894 to your computer and use it in GitHub Desktop.
rand5 to 7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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