diff options
Diffstat (limited to 'scratch/facebook')
-rw-r--r-- | scratch/facebook/moderate/rand7.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/scratch/facebook/moderate/rand7.py b/scratch/facebook/moderate/rand7.py index 19a96ed77b51..ed3a7cea80e5 100644 --- a/scratch/facebook/moderate/rand7.py +++ b/scratch/facebook/moderate/rand7.py @@ -8,15 +8,18 @@ from collections import Counter def rand5(): return random.randint(0,4) -def rand4(): - x = rand7() - if x >= 4: - return rand4() - return x - # Return [0,6] -def rand7(): +def rand7_a(): return sum(rand5() for _ in range(7)) % 7 -c = Counter([rand4() for _ in range(100000)]) +# Return [0,6] +def rand7_b(): + x = 5 * rand5() + rand5() + if x < 21: + return x % 7 + return rand7_b() + +c = Counter([rand7_a() for _ in range(100000)]) +print(c) +c = Counter([rand7_b() for _ in range(100000)]) print(c) |