问题描述:
笔者在Windows 64位平台跑一个在Ubuntu上运行正常的程序时,出现了以下报错:

具体为:
seed = np.random.randint(0, 2 ** 32) # make a seed with numpy generator
File "mtrand.pyx", line 763, in numpy.random.mtrand.RandomState.randint
File "_bounded_integers.pyx", line 1336, in numpy.random._bounded_integers._rand_int32
ValueError: high is out of bounds for int32
定位报错语句为:seed = np.random.randint(0, 2 ** 32)。
原因分析:
在Linux系统不报错,但是在Windows 64位系统下运行报错。查询资料发现1,numpy 默认的整数类型(integer type)np.int_ 是 C long2,但是C的long类型在win64平台下是 int323,而在其他系统下是 int64,因此产生报错。
解决方案:
- 缩小随机种子产生的范围4,即将
2 ** 32改为2 ** 31-1或2 ** 31。 - 明确定义整数类型5,即改为:
seed = np.random.randint(0, 2**32 - 1, dtype=np.int64)
numpy array dtype is coming as int32 by default in a windows 10 64 bit machine ↩︎
http://docs.scipy.org/doc/numpy-1.10.1/user/basics.types.html ↩︎
https://msdn.microsoft.com/en-us/library/9c3yd98k.aspx ↩︎
Bug: ValueError: high is out of bounds for int32 #1579 ↩︎
ValueError: high is out of bounds for int32 #20 ↩︎



![[CISCN2019 华北赛区 Day1 Web5]CyberPunk 二次报错注入](https://img-blog.csdnimg.cn/67c10ddf0c1341bb81864a67617a3346.png)















