Skip to content

Instantly share code, notes, and snippets.

@laalaguer
Created March 30, 2020 10:33
Show Gist options
  • Save laalaguer/6d455bed65bfba03ac3e16580f683fa8 to your computer and use it in GitHub Desktop.
Save laalaguer/6d455bed65bfba03ac3e16580f683fa8 to your computer and use it in GitHub Desktop.
The random possibilites
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