1

Follow up, if I manage to send two requests at EXACTLY the same time, does Math.Random() generate the same number?

3
  • 3
    I doubt they use time, look at the source code for the engines. Commented Jan 22, 2018 at 1:56
  • 2
    I presume you are asking because you want to use it as some kind of security feature. Do not use Math.random for security related stuff. Commented Jan 22, 2018 at 1:57
  • Possible duplicate of What algorithm does Math.random use? Commented Jan 22, 2018 at 2:14

1 Answer 1

4

The spec for Math.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.

Each Math.random function created for distinct realms must produce a distinct sequence of values from successive calls.

In other words, how the randomness is implemented depends entirely on the JavaScript engine, or browser. It may or may not use the current time as part of its implementation.

Relevant resources:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.