Code coverage report for sc/libs/random.js

Statements: 100% (31 / 31)      Branches: 100% (2 / 2)      Functions: 100% (9 / 9)      Lines: 100% (31 / 31)      Ignored: none     

All files » sc/libs/ » random.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 591     1   1 104     1 134 2   134 134 134 134 134 134   134 134 134   134     1 232 232 232 232     1 232     1   1   1     1     2     29     232        
(function(sc) {
  "use strict";
 
  require("./libs");
 
  function RandGen(seed) {
    this.setSeed(seed);
  }
 
  RandGen.prototype.setSeed = function(seed) {
    if (typeof seed !== "number") {
      seed = Date.now();
    }
    seed += ~(seed <<  15);
    seed ^=   seed >>> 10;
    seed +=   seed <<  3;
    seed ^=   seed >>> 6;
    seed += ~(seed <<  11);
    seed ^=   seed >>> 16;
 
    this.x = 1243598713 ^ seed;
    this.y = 3093459404 ^ seed;
    this.z = 1821928721 ^ seed;
 
    return this;
  };
 
  RandGen.prototype.trand = function() {
    this.x = ((this.x & 4294967294) << 12) ^ (((this.x << 13) ^ this.x) >>> 19);
    this.y = ((this.y & 4294967288) <<  4) ^ (((this.y <<  2) ^ this.y) >>> 25);
    this.z = ((this.z & 4294967280) << 17) ^ (((this.z <<  3) ^ this.z) >>> 11);
    return this.x ^ this.y ^ this.z;
  };
 
  RandGen.prototype.next = function() {
    return (this.trand() >>> 0) / 4294967296;
  };
 
  RandGen.prototype.RandGen = RandGen;
 
  var current = new RandGen();
 
  sc.libs.random = {
    RandGen: RandGen,
    getCurrent: function() {
      return current;
    },
    setCurrent: function(randgen) {
      current = randgen;
    },
    setSeed: function(seed) {
      return current.setSeed(seed);
    },
    next: function() {
      return current.next();
    }
  };
})(sc);