FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-37439 - Add random.binomialvariate() by avinassh · Pull Request #14530 · python/cpython · GitHub

Repository navigation

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 11 additions & 0 deletions Lib/random.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,17 @@ def weibullvariate(self, alpha, beta):
u = 1.0 - self.random()
return alpha * (-_log(u)) ** (1.0/beta)

## -------------------- Binomial distribution --------------------

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(self.random() < p for i in range(n))

## --------------- Operating System Random Source ------------------

class SystemRandom(Random):
Expand Down

Back | FazBrowse Home | New Git URL