Created
March 30, 2020 10:33
-
-
Save laalaguer/6d455bed65bfba03ac3e16580f683fa8 to your computer and use it in GitHub Desktop.
The random possibilites
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 | |
foo = random.SystemRandom() | |
threshold = 8 | |
at_least = 5 | |
bingo = 0 | |
experiment_times = 100000 | |
for i in range(experiment_times): | |
# build 100 numbers into a list, each number range from 0 to 101 | |
templist = [] | |
for i in range(100): | |
templist.append(foo.randint(0,101)) | |
# smaller than threshold | |
smaller_than_threshold = [] | |
for item in templist: | |
if item < threshold: | |
smaller_than_threshold.append(item) | |
if len(smaller_than_threshold) >= at_least: | |
bingo += 1 | |
print(bingo/experiment_times) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment