python生成随机数代码_用Python生成16位随机数

我请你小心你正在使用的随机数生成器。

我对生成的数字分布做了一个测试。

以下是我发现的: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')

rnOVb.jpg

正如我们所注意到的,这些方法是相同的。

然而,第二个数字[0:16]可以把0作为第一个数字,即15个数字。在

为什么不使用随机函数呢。在

^{pr2}$

5DZZ5.jpg

这样,你就可以得到一个16位数的正态分布。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值