python实现统计模拟【第3章】【伪随机数的产生】
#伪随机数的产生#生成(0,1)上的均匀分布
#方法1:乘同余法
def random_number1(seed = 1233223, m = pow(2, 31)-1, a = pow(7, 5), number = 10):
res = []
xi_1 = seed
for i in range(number):
xi = (a * xi_1)%m
res.append(xi/m)
xi_1 = xi
return res
temp = random_number1(number = 12)
print(temp)
#方法2:混合同余法
def random_number2(seed = 1233223, m = pow(2, 31)-1, c = 1,a = pow(7, 5), number = 10):
res = []
xi_1 = seed
for i in range(number):
xi = (a * xi_1 + c) % m
res.append(xi / m)
xi_1 = xi
return res
temp = random_number2(number = 10)
print(temp)
参考:
1.Sheldon M.Ross《统计模拟》
页:
[1]