1 // prng4.js - uses Arcfour as a PRNG
9 // Initialize arcfour context from key, an array of ints, each from [0..255]
10 function ARC4init(key) {
12 for(i = 0; i < 256; ++i)
15 for(i = 0; i < 256; ++i) {
16 j = (j + this.S[i] + key[i % key.length]) & 255;
18 this.S[i] = this.S[j];
27 this.i = (this.i + 1) & 255;
28 this.j = (this.j + this.S[this.i]) & 255;
30 this.S[this.i] = this.S[this.j];
32 return this.S[(t + this.S[this.i]) & 255];
35 Arcfour.prototype.init = ARC4init;
36 Arcfour.prototype.next = ARC4next;
38 // Plug in your RNG constructor here
39 function prng_newstate() {
43 // Pool size must be a multiple of 4 and greater than 32.
44 // An array of bytes the size of the pool will be passed to init()