dimanche 25 décembre 2022

How to select a number according to a uniform distribution from a set of first n natural numbers in python? [closed]

Suppose I have a set of the first n natural numbers, i.e., [n]:= {1,2,3,...n}. Now, I have to select one number from the set [n]. I want to select the number according to a uniform distribution. In other words, the probability that a number j in the set [n] will be selected is 1/n.

Here is what I have tried;

a = 2**33
b = np.random.randint(1, a)

but this code is giving me the following error:

ValueError: high is out of bounds for int32

Clearly, random.randint isn't working for me. So, how can I select a number according to the uniform distribution in Python?




Aucun commentaire:

Enregistrer un commentaire