// prng4.js - uses arcfour as a prng function arcfour() { this.i = 0; this.j = 0; this.s = new array(); } // initialize arcfour context from key, an array of ints, each from [0..255] function arc4init(key) { var i, j, t; for(i = 0; i < 256; ++i) this.s[i] = i; j = 0; for(i = 0; i < 256; ++i) { j = (j + this.s[i] + key[i % key.length]) & 255; t = this.s[i]; this.s[i] = this.s[j]; this.s[j] = t; } this.i = 0; this.j = 0; } function arc4next() { var t; this.i = (this.i + 1) & 255; this.j = (this.j + this.s[this.i]) & 255; t = this.s[this.i]; this.s[this.i] = this.s[this.j]; this.s[this.j] = t; return this.s[(t + this.s[this.i]) & 255]; } arcfour.prototype.init = arc4init; arcfour.prototype.next = arc4next; // plug in your rng constructor here function prng_newstate() { return new arcfour(); } // pool size must be a multiple of 4 and greater than 32. // an array of bytes the size of the pool will be passed to init() var rng_psize = 256;