# 4 examples of 'np random binomial' in Python

Every line of 'np random binomial' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``144def binomial(trials, p, shape=[]):145    """binomial(trials, p) or binomial(trials, p, [n, m, ...]) returns array of binomially distributed random integers.146147           trials is the number of trials in the binomial distribution.148           p is the probability of an event in each trial of the binomial distribution."""149    if shape == []:150        shape = None151    return mt.binomial(trials, p, shape)``
``76def test_binomial(self):77    assert self.rs.binomial(10, .5) &gt;= 078    assert self.rs.binomial(1000, .5) &gt;= 0``
``123def binomial(big, small):124    '''125    Get the binomial coefficient (big small).126    127    This is used in combinatorical calculations. More information:128    http://en.wikipedia.org/wiki/Binomial_coefficient129    '''130    if big == small:131        return 1132    if big &lt; small:133        return 0134    else:135        return (math.factorial(big) // math.factorial(big - small)136                                                      // math.factorial(small))``
``658def binomial_like(self, x, n, p, name='binomial', prior=False):659	"""Binomial log-likelihood"""660	661	if not shape(n) == shape(p): raise ParameterError, 'Parameters must have same dimensions'662	663	if ndim(n) &gt; 1:664		665		return sum([self.binomial_like(y, _n, _p, name, prior) for y, _n, _p in zip(x, n, p)])666	667	else:668		669		# Ensure valid values of parameters670		self.constrain(p, 0, 1)671		self.constrain(n, lower=x)672		self.constrain(x, 0)673		674		# Enforce array type675		x = atleast_1d(x)676		p = resize(p, shape(x))677		n = resize(n, shape(x))678		679		# Goodness-of-fit680		if self._gof and not prior:681			682			try:683				self._like_names.append(name)684			except AttributeError:685				pass686			687			expval = p * n688			689			# Simulated values690			y = array([rbinomial(_n, _p) for _n, _p in zip(n, p)])691			692			# Generate GOF points693			gof_points = sum(transpose([self.loss(x, expval), self.loss(y, expval)]))694			695			self._gof_loss.append(gof_points)696		697		return sum([fbinomial(xx, nn, pp) for xx, nn, pp in zip(x, n, p)])``