samedi 25 septembre 2021

Is python random.choices biased?

I might be forgetting some statistics basic in this one.

I ran the following experiment in python:

import random as r
bigger_than_zero=0
smaller_than_zero=0
for k in range(0,100):
    a=0
    for i in range(0,10000):
        a=a+r.choices([-4,-3,-2,1,0,1,2,3,4])[0]
    if a>0:
        bigger_than_zero+=1
    elif a<0:
        smaller_than_zero+=1
print(bigger_than_zero)
print(smaller_than_zero)

and the output was

100
0

well, since i determined no weights, shouldn't r.choices output a random integer between -4 and 4 each time? And since the probabilities are equal, shouldn't the average sum result after 10000 iterations be close to zero? And since it should be random, close to zero and normally distributed, shouldn't the bigger_than_zero and smaller_than_zero final results be at least close to each other (instead of the 100 and 0 results)?




Aucun commentaire:

Enregistrer un commentaire