我请你小心你正在使用的随机数生成器。
我对生成的数字分布做了一个测试。
以下是我发现的:import uuid
import numpy as np
import matplotlib.pyplot as plt
# Generation of 100000 numbers using the [0:8] + [0:8] technique
res1 = np.empty(shape=100000, dtype=int)
for i in xrange(res1.size):
tmp = str(uuid.uuid4().int>>64)[0:8] + str(uuid.uuid4().int>>64)[0:8]
res1[i] = int(tmp)
# Generation of 100000 numbers using the [0:16] technique
res2 = np.empty(shape=100000, dtype=int)
for i in xrange(res1.size):
tmp = str(uuid.uuid4().int>>64)[0:16]
res2[i] = int(tmp)
# Histogram plot
plt.setp(patches, 'facecolor', 'g', 'alpha', 0.75)
n, bins, patches = plt.hist(res1, 100, normed=1, histtype='stepfilled')
n, bins, patches = plt.hist(res2, 100, normed=1, histtype='stepfilled')
正如我们所注意到的,这些方法是相同的。
然而,第二个数字[0:16]可以把0作为第一个数字,即15个数字。在
为什么不使用随机函数呢。在
^{pr2}$
这样,你就可以得到一个16位数的正态分布。在