创建一个更随机的int? [英] Creating a more random int?

查看:70
本文介绍了创建一个更随机的int?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我需要从一个范围内检索一个整数...这个工作......下面

是我的输出。 ..它似乎没那么随意......


是否有一个建议可以创建一个更随机的int ...?

random.randint(3,8)
7 random.randint(3,8)
3 random.randint(3 ,8)
3 random.randint(3,8)
4 random.randint(3,8)
3 random.randint(3,8)
4 random.randint (3,8)
7 random.randint(3,8)
7 random.randint(3,8)
7 random.randint(3,8)
5随机.randint(3,8)
6 random.randint(3,8)
3 random.randint(3,8)
8 random.randint(3,8)
8 random.randint(3,8)
5 random.randint(3,8)
3 random.randint(3,8)



4


问候,

史蒂文

解决方案

" Steven Macintyre < ST **** @ steven.macintyre.name>写道:

我需要从一个范围内检索一个整数...这个工作......下面
是我的输出...它似乎不是那么随机...


对于随机小的整数来说,看起来很随意。

有一些统计测试表明prng肯定是失败了吗?

是否有建议可以创建一个更随机的int ...?




尝试从os.urandom中读取字节并将它们转换为

程序中的整数。




Steven Macintyre写道:

大家好,

我需要从一个范围内检索一个整数......这个工作......下面
是我的外出......它似乎没那么随意...


它有什么问题?

是也许有一个建议在那里创建一个更随机的int ...?


您认为输出应该是什么?


您对更随机的标准是什么?

random.randint(3,8)7 random.randint(3,8)3 random.randint(3,8)3 random.randint(3,8) )4 random.randint(3,8)3 random.randint(3,8)4 random.randint(3,8)7 random.randint(3,8)7 random.randint(3,8)7 random.randint (3,8)5 random.randint(3,8)6 random.randint(3,8)3 random.randint(3,8)8 random.randint(3,8)8 random.randint(3,8) 5 random.randint(3,8)3 random.randint(3,8)


4

问候,

史蒂文




On Tue,2006年1月24日18:47:01 +0200,Steven Macintyre写道:

大家好,

我需要从一个范围内检索一个整数...这个工作......下面
是我的出局...它似乎不是这样随机...


你是c从六个值开始。从长远来看,你应该期望每个值_bout_

的时间为17%。在你的17个样本的小样本上,你

得到这个:


7 3 3 4 3 4 7 7 7 5 6 3 8 8 5 3 4


3出现5次或29%

4出现3次或18%

5出现2次或12%

6出现一次或6%

7出现4次或23%

8出现两次或12%

>
对我来说非常随意。


只有17次试验,每个

的数量接近17%将是一个重大的奇迹。如果你真的得到这样的东西:


5 3 4 5 8 4 7 5 6 8 6 3 6 7 4 3 7


赔率非常强,不是很随机。首先,它是好的b $ b太好了,不可能。另一方面,没有重复的值。

确实没有重复值的可能性非常小。

是否有建议可以创建更多值random int ...?




23是最随机的int。也许你应该使用它。


但是除了开玩笑之外,Python使用的随机数生成器是世界上最好的之一。

。有什么不妥的是你对随机数看起来应该是什么样的直觉,而不是随机数生成器。

-

史蒂文。


Hi all,

I need to retrieve an integer from within a range ... this works ... below
is my out puts ... it just does not seem so random ...

Is there perhaps a suggestion out there to create a more random int ...?

random.randint(3, 8) 7 random.randint(3, 8) 3 random.randint(3, 8) 3 random.randint(3, 8) 4 random.randint(3, 8) 3 random.randint(3, 8) 4 random.randint(3, 8) 7 random.randint(3, 8) 7 random.randint(3, 8) 7 random.randint(3, 8) 5 random.randint(3, 8) 6 random.randint(3, 8) 3 random.randint(3, 8) 8 random.randint(3, 8) 8 random.randint(3, 8) 5 random.randint(3, 8) 3 random.randint(3, 8)


4

Regards,
Steven

解决方案

"Steven Macintyre" <st****@steven.macintyre.name> writes:

I need to retrieve an integer from within a range ... this works ... below
is my out puts ... it just does not seem so random ...
It''s pretty normal for random small ints to not look random. Are
there some statistical tests that the prng is definitely failing?
Is there perhaps a suggestion out there to create a more random int ...?



Try reading bytes from os.urandom and converting them to ints in your
program.



Steven Macintyre wrote:

Hi all,

I need to retrieve an integer from within a range ... this works ... below
is my out puts ... it just does not seem so random ...
What''s wrong with it?

Is there perhaps a suggestion out there to create a more random int ...?
What do you think the output should be?

What''s your criteria for "more random"?

random.randint(3, 8) 7 random.randint(3, 8) 3 random.randint(3, 8) 3 random.randint(3, 8) 4 random.randint(3, 8) 3 random.randint(3, 8) 4 random.randint(3, 8) 7 random.randint(3, 8) 7 random.randint(3, 8) 7 random.randint(3, 8) 5 random.randint(3, 8) 6 random.randint(3, 8) 3 random.randint(3, 8) 8 random.randint(3, 8) 8 random.randint(3, 8) 5 random.randint(3, 8) 3 random.randint(3, 8)


4

Regards,
Steven




On Tue, 24 Jan 2006 18:47:01 +0200, Steven Macintyre wrote:

Hi all,

I need to retrieve an integer from within a range ... this works ... below
is my out puts ... it just does not seem so random ...
You are choosing from six values. You should expect each value _about_
17% of the time, in the long-term. On your tiny sample of 17 samples, you
get this:

7 3 3 4 3 4 7 7 7 5 6 3 8 8 5 3 4

3 occurs five times or 29%
4 occurs three times or 18%
5 occurs two times or 12%
6 occurs one time or 6%
7 occurs four times or 23%
8 occurs two times or 12%

Looks pretty random to me.

With only 17 trials, it would be a major miracle to get near 17% for every
number. If you actually got something like this:

5 3 4 5 8 4 7 5 6 8 6 3 6 7 4 3 7

the odds are VERY strong that it is not really random. For one thing, it
is too good to be true. For another thing, there are no repeated values.
The chances of there being no repeated values is very small indeed.
Is there perhaps a suggestion out there to create a more random int ...?



23 is the most random int. Perhaps you should use that.

But all joking aside, the random number generator used by Python is one of
the best in the world. What is at fault is your intuition about what
random numbers should look like, not the random number generator.
--
Steven.


这篇关于创建一个更随机的int?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆