本文整理汇总了Python中random.paretovariate方法的典型用法代码示例。如果您正苦于以下问题:Python random.paretovariate方法的具体用法?Python random.paretovariate怎么用?Python random.paretovariate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类random
的用法示例。
在下文中一共展示了random.paretovariate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_random_text
# 需要导入模块: import random [as 别名]
# 或者: from random import paretovariate [as 别名]
def create_random_text(strs,slen,alpha):
'''
Create strs number of strings with length of slen
Use pareto distribution to pull randomly from 4 different groups
if Alpha is large (>10) get almost 100% letters,
if Alpha is smaller (1..5) get mixture of letters, numbers and special chars
See https://en.wikipedia.org/wiki/Pareto_distribution
'''
s = []
chrs = sorted(list(Morsecode))
groups =[[29,55],[12,22],[0,11],[55,60]] #letters 29-55, numbers 12-22
for i in range(strs):
for j in range(slen):
val = paretovariate(alpha)-1 #pareto distribution
gn = int((val, 3)[val > 3]) # select the group characters are pulled from
s += chrs[randrange(groups[gn][0],groups[gn][1])] #select random char from group
s += ' '
return ''.join(s)
示例2: get_dist
# 需要导入模块: import random [as 别名]
# 或者: from random import paretovariate [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)
示例3: fill_data
# 需要导入模块: import random [as 别名]
# 或者: from random import paretovariate [as 别名]
def fill_data(conn):
async with conn.begin():
for name in random.sample(names, len(names)):
uid = await conn.scalar(
users.insert().values(name=name, birthday=gen_birthday()))
emails_count = int(random.paretovariate(2))
for num in random.sample(range(10000), emails_count):
is_private = random.uniform(0, 1) < 0.8
await conn.execute(emails.insert().values(
user_id=uid,
email='{}+{}@gmail.com'.format(name, num),
private=is_private))
示例4: pareto_sequence
# 需要导入模块: import random [as 别名]
# 或者: from random import paretovariate [as 别名]
def pareto_sequence(n,exponent=1.0):
"""
Return sample sequence of length n from a Pareto distribution.
"""
return [random.paretovariate(exponent) for i in range(n)]
示例5: powerlaw_sequence
# 需要导入模块: import random [as 别名]
# 或者: from random import paretovariate [as 别名]
def powerlaw_sequence(n,exponent=2.0):
"""
Return sample sequence of length n from a power law distribution.
"""
return [random.paretovariate(exponent-1) for i in range(n)]
示例6: powerlaw_sequence
# 需要导入模块: import random [as 别名]
# 或者: from random import paretovariate [as 别名]
def powerlaw_sequence(n, exponent=2.0):
"""
Return sample sequence of length n from a power law distribution.
"""
return [random.paretovariate(exponent - 1) for i in range(n)]