Advertisement
AyrA

JS RNG

Jul 2nd, 2015
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Javascript random number generator, that allows to be seeded
  2. //quite high quality numbers even for its simplicity.
  3. //Suitable for simple random number generation (not crypto).
  4. //Since it allows seeding, it also allows the user to run this in sync with others.
  5. myrand=
  6. {
  7.     z:1,
  8.     w:2,
  9.     next:function(i)
  10.     {
  11.         myrand.z=36969*(myrand.z & 65535)+(myrand.z>>16);
  12.         myrand.w=18000*(myrand.w & 65535)+(myrand.w>>16);
  13.         var res=Math.abs(myrand.z<<16)+myrand.w;
  14.         return i?res%i:res;
  15.     },
  16.     seed:function(a,b)
  17.     {
  18.         myrand.z=Math.abs(a||1);
  19.         myrand.w=Math.abs(b||1);
  20.         if(a===undefined || b===undefined)
  21.         {
  22.             myrand.seed(myrand.next(),myrand.next());
  23.         }
  24.     }
  25. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement