How random is random.randint in python?
import random
x=0
for i in range(10000):
my_series = [random.randint(0, 11) for i in range(100)]
x += 1 if len(list(filter(lambda x: x % 2 == 1, my_series))) < len(list(filter(lambda x: x % 2 == 0, my_series))) else -1
print(x)
Why is the preponderance always in the negative even though the list generation is random and the possible number of even and odd values is the same(from 0 to 11).
0
Author: Michael Larshin, 2019-11-30
1 answers
Because the cases where even and odd are the same are considered in -1.
If the list my_series
is made of odd length, then х
will fluctuate around 0 (although there may be quite significant deviations).
4
Author: Эникейщик, 2019-11-30 22:05:50