简体   繁体   English

JavaScript-Math.random()-参数

[英]JavaScript - Math.random() - parameter

What changes adding the parameter in Math.random() ? Math.random()添加参数Math.random()什么变化?

For example: 例如:

Math.random() == Math.random(1234)

Math.random doesn't take params. Math.random不带参数。

If you want to generate a random number between 2 intervals (a and b) you can use the formula: 如果要生成两个间隔(a和b)之间的随机数,可以使用以下公式:

math.random()*(b-a)+a

Read the specification : 阅读规范

15.8.2.14 random ( ) 15.8.2.14随机()

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. 使用依赖于实现的算法或策略,返回一个正号的数字值,该值大于或等于0但小于1,在该范围内随机选择或伪随机选择,并且在该范围内具有近似均匀的分布。 This function takes no arguments. 此函数不带参数。

Nothing. 没有。 There is no seed for Math.random in Javascript. Javascript中没有Math.random种子。 Anything inside the function call will just be dropped. 函数调用中的所有内容都将被删除。

No official parameters. 没有官方参数。 Have a look here: https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math/random 在这里看看: https : //developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math/random

The confusion is understandable. 混乱是可以理解的。 Several sites have a seed in the function since it came from C / Java. 由于它来自C / Java,因此有几个站点在该函数中具有种子。 More information about this ignored parameter here: Math.random() - Not random 有关此被忽略参数的更多信息,请参见Math.random()-非随机

If you want a better random number get one from here http://www.random.org/clients/http/ - you will need to wrap it in some server based client - see here for more information Cross domain ajax request from javascript file without help of server side code 如果您想获得更好的随机数,请从此处获取一个http://www.random.org/clients/http/-您需要将其包装在一些基于服务器的客户端中-有关详细信息,请参见此处。 来自javascript文件的跨域ajax请求无需服务器端代码的帮助

UPDATE: Emailed the creator of random.org - he replied he is working on a jsonp implementation... 更新:通过电子邮件发送了random.org的创建者-他回答说他正在研究jsonp实现...

它将忽略传递的参数。

它没有Math.random()没有任何参数... :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM