4

Since I've been studying Computer Science, whenever random numbers come up, it's always Mersenne Twister. There's never even a question, no alternative. Just, use Mersenne Twister.

So what does JavaScript's Math.random use? It seems like it ought to use Mersenne Twister, since it's apparently without peer, but I can't find any reference to whether it does or not.

Does anyone know what it relies on, and/or why it isn't MT, if that's the case?

1
  • Quantum computing offers algorithms that can generate more "natural" random numbers. [Theoretically] Commented Apr 28, 2012 at 7:24

1 Answer 1

7

It's likely implementation specific. The ECMAScript specification does not force any algorithm, so a Linux JavaScript implementation might very well use /dev/urandom.

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

2 Comments

I didn't know there were multiple implementations of JavaScript? I'm not very experienced with web development. I was under the impression all JavaScript was the same.
@Aerovistae, JavaScript conforms to a specification, and the specification does not explicitly state which algorithm should be used for random numbers. There are many implementations of the language, such as the V8 engine used by Chrome, or SpiderMonkey used by Firefox. Also, JavaScript is a general purpose language not limited to the browser, so it can and does run on the server side as well, with frameworks such as node.js and even in database servers such as MongoDB.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.