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?

temporary_user_name
  • 35,956
  • 47
  • 141
  • 220
  • Quantum computing offers algorithms that can generate more "natural" random numbers. [Theoretically] – KBN Apr 28 '12 at 07:24

1 Answers1

8

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

rid
  • 61,078
  • 31
  • 152
  • 193
  • 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. – temporary_user_name Apr 28 '12 at 07:23
  • @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](http://code.google.com/p/v8/) used by Chrome, or [SpiderMonkey](https://developer.mozilla.org/en/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](http://nodejs.org/) and even in database servers such as [MongoDB](http://mongodb.org). – rid Apr 28 '12 at 07:30