Random Number Generators

JavaScript performance comparison

Revision 2 of this test case created by Josh

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var seed, seeder, seedlast;
   
    function setSeed() {
      seeder = 1777771 / (seed = (Math.round(Math.random() * 10000000))); // 1777771 is prime
      seedlast = .007;
    }
   
    function getSeed() {
      return seedlast = "0." + String(seeder / seedlast).substring(4).replace('.', '');
    }
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Built-in
Math.random();
pending…
Mine
getSeed();
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment