马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#伪随机数的产生
#生成(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《统计模拟》 |