Math.random()算法 [英] Math.random() algorithm

查看:80
本文介绍了Math.random()算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于Math.random(),ECMA 262只是说返回一个带有

正号的数字值,大于或等于0但小于1,随机选择

或伪随机,在

范围内大致均匀分布,使用依赖于实现的算法或策略。


这还不够好为了我的目的(生成标识符

足够的熵,比如256位左右,有效地排除任何两次调用的任何机会

)可能是一个起点。


有没有人在各种

实现中有关于Math.random()函数的信息?


更一般地说,有没有可靠的方法来获取良好的噪音,除了

,通过设置服务器并用XMLHTTRequest调用它?


-

Johannes

" Quand on dit c''est un Johannes,cela vaut autant que ce que mainten蚂蚁

on appelle un p ?? dant (H. Estienne,在Littr ??,art.P ?? DANT)

About Math.random(), ECMA 262 just says "Returns a number value with
positive sign, greater than or equal to 0 but less than 1, chosen randomly
or pseudo randomly with approximately uniform distribution over that
range, using an implementation-dependent algorithm or strategy."

This is not good enough for my purposes (to generate identifiers with
sufficient entropy, say 256 bits or so, to effectively preclude any chance
of any two calls ever pricking the same), but it may be a starting point.

Does anyone have information about the Math.random() function in various
implementations?

More generally, is there any reliable way of picking up good noise, except
by setting up a server and calling it, say, with XMLHTTRequest?

--
Johannes
"Quand on dit c''est un Johannes, cela vaut autant que ce que maintenant
on appelle un p??dant" (H. Estienne, in Littr??, art. P??DANT)

推荐答案

Johannes Baagoe写道:
Johannes Baagoe wrote:

关于Math.random(),ECMA 262只是说返回一个带有

正号的数字值,大于或等于0但小于1,随机选择

或伪随机,在

范围内大致均匀分布,使用依赖于实现的算法或策略。


这对我的目的来说还不够好(生成带有足够熵的标识符,比如256位左右),以有效排除任何两次调用的任何机会

相同),但它可能是一个起点。


有没有人在各种

实现中有关于Math.random()函数的信息?
About Math.random(), ECMA 262 just says "Returns a number value with
positive sign, greater than or equal to 0 but less than 1, chosen randomly
or pseudo randomly with approximately uniform distribution over that
range, using an implementation-dependent algorithm or strategy."

This is not good enough for my purposes (to generate identifiers with
sufficient entropy, say 256 bits or so, to effectively preclude any chance
of any two calls ever pricking the same), but it may be a starting point.

Does anyone have information about the Math.random() function in various
implementations?

http:// www。 merlyn.demon.co.uk/js-randm.htm 应该让你忙着


http://www.merlyn.demon.co.uk/js-randm.htm should keep you busy for a
while.


更多通常,有没有可靠的方法来获取良好的噪音,除了

,通过设置服务器并用XMLHTTRequest调用它?
More generally, is there any reliable way of picking up good noise, except
by setting up a server and calling it, say, with XMLHTTRequest?



var unique_url =''file.php?''+(new Date())。getTime();


希望这会有所帮助,


-

巴特

var unique_url = ''file.php?'' + (new Date()).getTime();

Hope this helps,

--
Bart


Bart Van der Donck:
Bart Van der Donck :

Johannes Baagoe:
Johannes Baagoe :


> ;有没有人在各种
实现中有关于Math.random()函数的信息?
>Does anyone have information about the Math.random() function in various
implementations?

http://www.merlyn.demon.co.uk/js-randm.htm 应该让你忙着


http://www.merlyn.demon.co.uk/js-randm.htm should keep you busy for a
while.



大约半个小时,因为有趣的东西似乎是脱机的。


但如果与Borland平行Pascal / Delphi是有效的,算法

会是很好的旧线性同余吗?* la Lehmer,这对于浮点随机函数来说都是一点点b / b
当然不是很好

足够特别适合种植时间可预测的东西。

About half an hour, since the interesting stuff appears to be off-line.

But if the parallel with Borland Pascal/Delphi is valid, the algorithm
would be good old linear congruential ?* la Lehmer, which is both a bit
surprising for floating point random functions and certainly not good
enough especially when seeded with something as predictable as time.


>更一般地说,是否有任何可靠的方法来获取良好的噪音,
除了设置服务器并用XMLHTTRequest调用它之外?
>More generally, is there any reliable way of picking up good noise,
except by setting up a server and calling it, say, with XMLHTTRequest?


var unique_url =''file.php?''+(new Date())。getTime();
var unique_url = ''file.php?'' + (new Date()).getTime();



这肯定不符合*好*噪音,对不起......

http://www.random.org/integers /?num =...col = 16& base = 16

更符合我的要求。

That most certainly does not qualify as *good* noise, sorry...

http://www.random.org/integers/?num=...col=16&base=16
is more in line with what I want.


希望这有助于
Hope this helps



它确实在某种程度上确定了否定值总是有用的。


-

Johannes

" Quand on dit c''est un Johannes,cela vaut autant que ce que maintenant

on appelle un p ?? dant" ; (H. Estienne,cit ?? dans le Littr ??,art.P ?? DANT)

It did, to a certain extent: ascertaining a negative is always useful.

--
Johannes
"Quand on dit c''est un Johannes, cela vaut autant que ce que maintenant
on appelle un p??dant" (H. Estienne, cit?? dans le Littr??, art. P??DANT)


Johannes Baagoe写道:
Johannes Baagoe wrote:

关于Math.random(),ECMA 262只是说返回一个带有

正号的数值,大于或等于0但小于1,随机选择

或伪随机,在

范围内大致均匀分布,使用依赖于实现的算法或策略。


这是对我的目的来说还不够好(生成带有

足够熵的标识符,比如256位左右,以有效排除任何两次调用的任何机会

) ,但它可能是一个起点。


有没有人在各种

实现中有关于Math.random()函数的信息?


更一般地说,有没有可靠的方法来获取良好的噪音,除了

,通过设置服务器并调用它,比如说,使用XMLHTTRequest?
About Math.random(), ECMA 262 just says "Returns a number value with
positive sign, greater than or equal to 0 but less than 1, chosen randomly
or pseudo randomly with approximately uniform distribution over that
range, using an implementation-dependent algorithm or strategy."

This is not good enough for my purposes (to generate identifiers with
sufficient entropy, say 256 bits or so, to effectively preclude any chance
of any two calls ever pricking the same), but it may be a starting point.

Does anyone have information about the Math.random() function in various
implementations?

More generally, is there any reliable way of picking up good noise, except
by setting up a server and calling it, say, with XMLHTTRequest?



约翰内斯,


对你当前的任务很重要。

你没告诉我们为什么你需要256位熵,但如果你使用

javascript你会依赖OS /浏览器。

所以你很难找到哪个OS /浏览器组合做什么。很多

一份工作。

除非你找到一个值得信赖的好网页,总结一下。 (我做了一个

的快速搜索,但可以找到一个。)


我认为你可能更好的在
上使用一个好的随机包
服务器。

如果您需要1000个号码,只需让服务器生成1000个好的

随机数。

并获取它们使用XMLHTTRequest。

为什么你要避免这个解决方案(你已经给了自己)?


甚至使用由核生成的REAL随机字节辐射。

例如: http:// www。 fourmilab.ch/hotbits/how3.html


不确定这会有所帮助。 ;-)

祝你好运。


问候,

Erwin Moller

Hi Johannes,

Personally I WOULD go serverside if the ''quality'' of the random numbers
is important for your current task.
You didn''t tell us why you need 256 bits of entropy, but if you use
javascript you will stay OS/Browser dependent.
So you''re stuck with finding out which OS/browser combi does what. Quite
a job.
Unless you find a nice trustworthy webpage that sums it all up. (I did a
quick search but could find one.)

I think you are probably better of using a good random package on the
server.
In case you need 1000 numbers, just let the server generate 1000 good
random numbers.
And get them in with a XMLHTTRequest.
Why do you want to avoid that solution (you gave yourself already)?

Or even use REAL random bytes, generated by nuclear radiation.
eg: http://www.fourmilab.ch/hotbits/how3.html

Not sure this helped. ;-)
Good luck.

Regards,
Erwin Moller


这篇关于Math.random()算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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