本文整理汇总了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)