JavaScript - Math.random() - 参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6028649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript - Math.random() - parameter
提问by asifg
What changes adding the parameter in Math.random()
?
添加参数有什么变化Math.random()
?
For example:
例如:
Math.random() == Math.random(1234)
回答by CristiC
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:
如果要在 2 个区间(a 和 b)之间生成一个随机数,可以使用以下公式:
math.random()*(b-a)+a
回答by RobG
Read the specification:
阅读规范:
15.8.2.14 random ( )
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 function takes no arguments.
15.8.2.14 随机 ( )
使用依赖于实现的算法或策略,返回一个具有正号的数字值,大于或等于 0 但小于 1,随机或伪随机选择,在该范围内具有近似均匀分布。这个函数没有参数。
回答by John Green
Nothing. There is no seed for Math.random
in Javascript. Anything inside the function call will just be dropped.
没有什么。Math.random
在 Javascript 中没有种子。函数调用中的任何内容都将被删除。
回答by mplungjan
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. More information about this ignored parameter here: Math.random() - Not random
混乱是可以理解的。由于它来自 C/Java,因此有几个站点在该函数中有一个种子。关于这里忽略的参数的更多信息:Math.random() - Not 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 实现......
回答by Amareswar
It will just ignore the passed parameter.
它只会忽略传递的参数。
回答by chrisf
It doesn't - Math.random()
doesn't take any parameters... :)
它没有 -Math.random()
不带任何参数...... :)