本文整理匯總了Python中random.gammavariate方法的典型用法代碼示例。如果您正苦於以下問題:Python random.gammavariate方法的具體用法?Python random.gammavariate怎麽用?Python random.gammavariate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類random
的用法示例。
在下文中一共展示了random.gammavariate方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_zeroinputs
# 需要導入模塊: import random [as 別名]
# 或者: from random import gammavariate [as 別名]
def test_zeroinputs(self):
# Verify that distributions can handle a series of zero inputs'
g = random.Random()
x = [g.random() for i in range(50)] + [0.0]*5
g.random = x[:].pop; g.uniform(1,10)
g.random = x[:].pop; g.paretovariate(1.0)
g.random = x[:].pop; g.expovariate(1.0)
g.random = x[:].pop; g.weibullvariate(1.0, 1.0)
g.random = x[:].pop; g.vonmisesvariate(1.0, 1.0)
g.random = x[:].pop; g.normalvariate(0.0, 1.0)
g.random = x[:].pop; g.gauss(0.0, 1.0)
g.random = x[:].pop; g.lognormvariate(0.0, 1.0)
g.random = x[:].pop; g.vonmisesvariate(0.0, 1.0)
g.random = x[:].pop; g.gammavariate(0.01, 1.0)
g.random = x[:].pop; g.gammavariate(1.0, 1.0)
g.random = x[:].pop; g.gammavariate(200.0, 1.0)
g.random = x[:].pop; g.betavariate(3.0, 3.0)
g.random = x[:].pop; g.triangular(0.0, 1.0, 1.0/3.0)
示例2: test_endpoints_run
# 需要導入模塊: import random [as 別名]
# 或者: from random import gammavariate [as 別名]
def test_endpoints_run(deferred_endpoint):
'''Test that each endpoint is callable.
This takes a very, very long time in total (10-20 minutes) because we don't
want to barrage the NBA site with requests.'''
# Delay briefly
wait = random.gammavariate(alpha=9, beta=0.4)
time.sleep(wait)
# Call the API.
try:
response = deferred_endpoint()
except json.decoder.JSONDecodeError:
endpoint_class = deferred_endpoint.endpoint_class
msg = 'Unable to decode response for {}'.format(endpoint_class)
pytest.fail(msg=msg)
# We want to hang onto all the responses so we don't need to re-retrieve
# them later.
cached_eps.append(response)
示例3: get_dist
# 需要導入模塊: import random [as 別名]
# 或者: from random import gammavariate [as 別名]
def get_dist(d):
return {
'randrange': random.randrange, # start, stop, step
'randint': random.randint, # a, b
'random': random.random,
'uniform': random, # a, b
'triangular': random.triangular, # low, high, mode
'beta': random.betavariate, # alpha, beta
'expo': random.expovariate, # lambda
'gamma': random.gammavariate, # alpha, beta
'gauss': random.gauss, # mu, sigma
'lognorm': random.lognormvariate, # mu, sigma
'normal': random.normalvariate, # mu, sigma
'vonmises': random.vonmisesvariate, # mu, kappa
'pareto': random.paretovariate, # alpha
'weibull': random.weibullvariate # alpha, beta
}.get(d)
示例4: _fix
# 需要導入模塊: import random [as 別名]
# 或者: from random import gammavariate [as 別名]
def _fix(self):
return int(round(random.gammavariate(self.alpha, self.beta)))
示例5: test_gammavariate_errors
# 需要導入模塊: import random [as 別名]
# 或者: from random import gammavariate [as 別名]
def test_gammavariate_errors(self):
# Both alpha and beta must be > 0.0
self.assertRaises(ValueError, random.gammavariate, -1, 3)
self.assertRaises(ValueError, random.gammavariate, 0, 2)
self.assertRaises(ValueError, random.gammavariate, 2, 0)
self.assertRaises(ValueError, random.gammavariate, 1, -3)
示例6: rand_student_t
# 需要導入模塊: import random [as 別名]
# 或者: from random import gammavariate [as 別名]
def rand_student_t(df, mu=0, std=1):
"""
return random number distributed by student's t distribution with
`df` degrees of freedom with the specified mean and standard deviation.
"""
x = random.gauss(0, std)
y = 2.0*random.gammavariate(0.5 * df, 2.0)
return x / (math.sqrt(y / df)) + mu
示例7: poisson_latency
# 需要導入模塊: import random [as 別名]
# 或者: from random import gammavariate [as 別名]
def poisson_latency(latency):
return lambda: 1 + int(random.gammavariate(1, 1) * latency)