Message346815
This a small snippet of code I written dozens of times. It would be nice to have this in the library along with the other distributions.
def binomialvariate(n, p):
''' Binomial distribution for the number of successes
in *n* Bernoulli trials each with a probability *p*
of success.
Returns an integer in the range: 0 <= X <= n
'''
return sum(random() < p for i in range(n)) |
|
Date |
User |
Action |
Args |
2019-06-28 09:28:09 | rhettinger | set | recipients:
+ rhettinger, tim.peters, mark.dickinson |
2019-06-28 09:28:09 | rhettinger | set | messageid: <1561714089.16.0.904652961331.issue37439@roundup.psfhosted.org> |
2019-06-28 09:28:09 | rhettinger | link | issue37439 messages |
2019-06-28 09:28:09 | rhettinger | create | |
|