Skip to content

Instantly share code, notes, and snippets.

@inspirit
Created June 24, 2011 18:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inspirit/1045410 to your computer and use it in GitHub Desktop.
Save inspirit/1045410 to your computer and use it in GitHub Desktop.
A 32-bit random number generator by George Marsaglia
var __x:uint = 123456789;
var __y:uint = 362436069;
var __z:uint = 21288629;
var __w:uint = 14921776;
var __c:uint = 0;
function rnd():uint
{
__x = __x + 545925293;
__y = __y ^ (__y<<13);
__y = __y ^ (__y>>17);
__y = __y ^ (__y<<5);
var t:uint = __z + __w + __c;
__z = __w;
__c = (t >> 31);
__w = t & 2147483647;
return (__x + __y + __w);
}
function random():Number
{
return (rnd()*2.32830643708e-10); // 1 / 2^32
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment