获取随机,唯一的数字 [英] Getting random, unique numbers

查看:89
本文介绍了获取随机,唯一的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这将是原创的。我承诺。


我无法让随机数发生器工作。


我尝试使用Date.Now.Milliseconds播种,它仍会产生相同的值。


我所拥有的是值数组。


我得到每个数组的随机索引值,这样我就可以从中获取数据。


除了每次运行的数据都相似。


我知道它的时间问题,因为当我单步执行代码时,它会给我带来随机性。


但是,有什么比我可以播种的速度快几毫秒?


这是我的代码。如果您需要我解释一下,请告诉我。基本上,我正在创建一个随机数学表达式:

This will be original. I promise.

I cannot get the random number generator to work.

I tried seeding with Date.Now.Milliseconds, it still results in the same values.

What I have are arrays of values.

I get a random index value for each array so I can pull the data from them.

Except the data is similar on every run.

I know its a timing issue because when I step through code, it gives me randoms.

However, is there anything faster than milliseconds that I can seed at?

Here''s my code. Please let me know if you need me to explain anything. Basically, i''m creating a random math expression:

展开 | 选择 | Wrap | 行号

推荐答案

I发布此之前,但没有得到答复,所以我会再次尝试,不用细节稀释。


真的简单地说:即使我以毫秒为单位播种,随机数也不是随机的。


是否还有其他种子方法或其他具体的随机函数逻辑?
I posted this before but did not get a reply so i''m gonna try it again without diluting with detail.

Real simply put: random numbers are not random even though I seed with time in milliseconds.

Is there some other method to seed or some other concrete randomizer logic that works?


是的,程序通常只生成伪随机数。如果你想要真正的随机性,那么你必须观察一些自然随机的活动(如原子的运动)。在实践中虽然伪随机数就足够了。
Yep, programs usually only generate pseudo random numbers. If you want real randomness then you''d have to observe some naturally random activities (like movement of atoms). In practice though pseudo random numbers suffice.


如果您认为您的原始问题被忽略了,请回复原始帖子。这将再次将其提升到列表的顶部。请不要发新帖子。请阅读发布指南


我已合并你的主题。


主持人
If you feel that your original question has been overlooked, please just reply to the original thread. That will bump it to the top of the list again. Please do not make a new post. Please read the Posting Guidelines.

I have merged your threads.

MODERATOR


这篇关于获取随机,唯一的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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