import random
import seaborn as sns
import matplotlib.pyplot as plt
# 解决中文不显示的问题
from pylab import mpl
mpl.rcParams['font.sans-serif']=['SimHei']
# 解决正负号不显示问题
plt.rcParams['axes.unicode_minus']=False
random.random() # 返回随机生成的一个实数,它在[0,1)范围内。
random.randint(1,10) # 产生 1 到 10 的一个整数型随机数
random.randrange(1,100,2) # 生成从1到100的间隔为2的随机整数
random.uniform(1.1,5.4) # 产生 1.1 到 5.4 之间的随机浮点数,区间可以不是整数
random.choice('tomorrow') # 从序列中随机选取一个元素
random.sample('zyxwvutsrqponmlkjihgfedcba',5) # 多个字符中生成指定数量的随机字符
# 打乱排序
items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
random.shuffle(items)
print(items)
items:[3, 8, 4, 1, 7, 0, 6, 2, 9, 5]
n = 10000
x = [random.triangular(1, 10, 2) for i in range(n)]
sns.distplot(x) # 默认
n = 10000
x = [random.expovariate(1) for i in range(n)]
sns.distplot(x) # 默认
n = 10000
x = [random.betavariate(1, 1) for i in range(n)]
sns.distplot(x) # 默认
n = 10000
x = [random.gammavariate(10, 10) for i in range(n)]
sns.distplot(x) # 默认
n = 10000
x = [random.gauss(10, 1) for i in range(n)]
sns.distplot(x) # 默认
n = 10000
x = [random.lognormvariate(-100, 1) for i in range(n)]
sns.distplot(x) # 默认
n = 10000
x = [random.normalvariate(100, 10) for i in range(n)]
sns.distplot(x) # 默认
n = 10000
x = [random.vonmisesvariate(4, 0) for i in range(n)]
sns.distplot(x) # 默认
n = 10000
x = [random.paretovariate(100) for i in range(n)]
sns.distplot(x) # 默认
n = 10000
x = [random.weibullvariate(100,10) for i in range(n)]
sns.distplot(x) # 默认