jeudi 17 octobre 2019

Testing the hypothesis of even distribution of random numbers in python

I need to generate random numbers and test hypothesis of even distribution of them using any criteria. I generate numbers in the next way:

import numpy as np
from scipy import stats
import collections

np.random.seed(945925321)
nums = []
for i in range(100000):
    nums.append(np.random.random())

Than I find the frequency of the number:

res = []
counter = collections.Counter(nums)
for item in counter.values():
    res.append(item)

And use a chi square criteria to test the hypothesis:

print(stats.chisquare(res))

I always get a p-value equal to 1. Of course I can round numbers to increase their frequences, but that probably not the right way to do it. Is this a right way to generate number and check the hypothesis?




Aucun commentaire:

Enregistrer un commentaire