dojox/math/random/Secure.js

  • Provides:

    • dojox.math.random.Secure
  • dojox.math.random.Secure

    • type
      Function
    • summary
      Intializes an instance of a secure random generator.
    • parameters:
      • prng: (typeof Function)
        function that returns an instance of PRNG (pseudorandom number generator)
        with two methods: init(array) and next(). It should have a property "size"
        to indicate the required pool size.
      • noEvents: (typeof Boolean)
        if false or absent, onclick and onkeypress event will be used to add
        "randomness", otherwise events will not be used.
    • source: [view]
        this.prng = prng;


        // Initialize the pool with junk if needed.
        var p = this.pool = new Array(prng.size);
        this.pptr = 0;
        for(var i = 0, len = prng.size; i < len;) { // extract some randomness from Math.random()
         var t = Math.floor(65536 * Math.random());
         p[i++] = t >>> 8;
         p[i++] = t & 255;
        }
        this.seedTime();


        if(!noEvents){
         this.h = [
          dojo.connect(dojo.body(), "onclick", this, "seedTime"),
          dojo.connect(dojo.body(), "onkeypress", this, "seedTime")
         ];
        }
  • dojox.math.random.Secure.destroy

    • type
      Function
    • source: [view]
        if(this.h){
         dojo.forEach(this.h, dojo.disconnect);
        }
    • summary
      Disconnects events, if any, preparing the object for GC.
  • dojox.math.random.Secure.nextBytes

    • type
      Function
    • parameters:
      • byteArray: (typeof Array)
        array to be filled in with random numbers, only existing
        elements will be filled.
    • source: [view]
        var state = this.state;


        if(!state){
         this.seedTime();
         state = this.state = this.prng();
         state.init(this.pool);
         for(var p = this.pool, i = 0, len = p.length; i < len; p[i++] = 0);
         this.pptr = 0;
         //this.pool = null;
        }


        for(var i = 0, len = byteArray.length; i < len; ++i){
         byteArray[i] = state.next();
        }
    • summary
      Fills in an array of bytes with random numbers
  • dojox.math.random.Secure.seedTime

    • type
      Function
    • source: [view]
        this._seed_int(new Date().getTime());
    • summary
      Mix in the current time (w/milliseconds) into the pool
  • dojox.math.random.Secure._seed_int

    • type
      Function
    • parameters:
      • x: (typeof )
    • source: [view]
        var p = this.pool, i = this.pptr;
        p[i++] ^= x & 255;
        p[i++] ^= (x >> 8) & 255;
        p[i++] ^= (x >> 16) & 255;
        p[i++] ^= (x >> 24) & 255;
        if(i >= this.prng.size){
         i -= this.prng.size;
        }
        this.pptr = i;
    • summary
      Mix in a 32-bit integer into the pool
  • dojox.math.random.Secure.state

    • summary
  • dojox.math.random.Secure.pptr

    • summary
  • dojox.math.random.Secure.prng

    • type
      Function
    • summary
      function that returns an instance of PRNG (pseudorandom number generator)
      with two methods: init(array) and next(). It should have a property &quot;size&quot;
      to indicate the required pool size.
  • dojox.math.random.Secure.pool

    • summary
  • dojox.math.random.Secure.h

    • summary
  • dojox.math.random

    • type
      Object
    • summary
  • dojox.math

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary