简体   繁体   中英

JavaScript - Math.random() - parameter

What changes adding the parameter in Math.random() ?

For example:

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

Math.random doesn't take params.

If you want to generate a random number between 2 intervals (a and b) you can use the formula:

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

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.

Nothing. There is no seed for Math.random in Javascript. 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

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

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

UPDATE: Emailed the creator of random.org - he replied he is working on a jsonp implementation...

它将忽略传递的参数。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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