home *** CD-ROM | disk | FTP | other *** search
/ Il Mio Computer 2006 May / Mico05CD.bin / Utility / CryptoMX / mod.js < prev    next >
Encoding:
Text File  |  2006-01-05  |  1.1 KB  |  58 lines

  1. function uGen(old, a, q, r, m) {
  2.     var t;
  3.  
  4.     t = Math.floor(old / q);
  5.     t = a * (old - (t * q)) - (t * r);
  6.     return Math.round((t < 0) ? (t + m) : t);
  7. }
  8.  
  9. function LEnext() { 
  10.     var i;
  11.  
  12.     this.gen1 = uGen(this.gen1, 40014, 53668, 12211, 2147483563);
  13.     this.gen2 = uGen(this.gen2, 40692, 52774, 3791, 2147483399);
  14.  
  15.     i = Math.floor(this.state / 67108862);
  16.  
  17.     this.state = Math.round((this.shuffle[i] + this.gen2) % 2147483563);
  18.  
  19.     this.shuffle[i] = this.gen1;
  20.  
  21.     return this.state;
  22. }
  23.  
  24. function LEnint(n) {
  25.     var p = 1;
  26.  
  27.     while (n >= p) {
  28.     p <<= 1;
  29.     }
  30.     p--;
  31.  
  32.     while (true) {
  33.         var v = this.next() & p;
  34.  
  35.     if (v <= n) {
  36.         return v;
  37.     }
  38.     }
  39. }
  40.  
  41. function LEcuyer(s) {
  42.     var i;
  43.  
  44.     this.shuffle = new Array(32);
  45.     this.gen1 = this.gen2 = (s & 0x7FFFFFFF);
  46.     for (i = 0; i < 19; i++) {
  47.         this.gen1 = uGen(this.gen1, 40014, 53668, 12211, 2147483563);
  48.     }
  49.  
  50.     for (i = 0; i < 32; i++) {
  51.         this.gen1 = uGen(this.gen1, 40014, 53668, 12211, 2147483563);
  52.         this.shuffle[31 - i] = this.gen1;
  53.     }
  54.     this.state = this.shuffle[0];
  55.     this.next = LEnext;
  56.     this.nextInt = LEnint;
  57. }
  58.