- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex50.py
More file actions
Latest commit
29 lines (29 loc) · 726 Bytes
/
Copy pathex50.py
File metadata and controls
29 lines (29 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'''
输出一个随机数。
'''
importnumpyasnp
frommatplotlibimportpyplotasplt
figure=plt.figure()
# 线性同余法(Xn+1=(aXn+c) mod m)生成(0,1)的100000个随机数
a=214013
c=2531011
m=2**32
x=1
l= []
count_l=[]
foriinrange(100000):
x= (a*x+c) %m
l.append(x/m)
print(x/m)
# 验证生成的伪随机数是否均匀
foriinrange(10):
s=0
forjinl:
ifi/10<=j< (i+1)/10:
s+=1
count_l.append(s/100000)
print("处于不同区间的伪随机数频率分别为:")
print(count_l)
plt.hist(np.array(l), bins=10)
figure.show()
print("从列表以及图中可以看出,生成的伪随机数分散较均匀。")