I would like to have a program that calls a random funtcion which gives either 0,1,2 as result for a defined number of times and counts the result for each run. With using the random.randrange(0,3) I get an equal distribution.
How can I get a distribution with the following probability.
0: 0.4633
1: 0.3147
2: 0.2218
These numbers are variables that I calculated in a different function and they change after I run the function again.
import random
zeros = 0
ones = 0
twos = 0
for i in range(10000):
a = random.randrange(0,3)
if a == 0:
zeros = zeros + 1
if a == 1:
ones = ones + 1
if a == 2:
twos = twos + 1
print "zeros = ", zeros
print "ones = ", ones
print "twos = ", twos
zeros = 3345
ones = 3326
twos = 3329
Wanted:
zeros = 4633
ones = 3147
twos = 2218
Thank you in advance :)
Aucun commentaire:
Enregistrer un commentaire