Multiply With Carry

This algorithm generates a random number.



									private static uint[] Q = new uint[4096];
private static uint c = 362436; 
private static uint i = 4095;

public static uint MultiplyWithCarry()
{
	ulong t, a = 18782;
	uint x, r = 0xfffffffe;

	i = (i + 1) & 4095;
	t = a * Q[i] + c;
	c = (uint)(t >> 32);
	x = (uint)t + c;

	if (x < c)
	{
		x++;
		c++;
	}

	return (Q[i] = r - x);
}
								


Example

									uint value = MultiplyWithCarry();
								


Output

									4294604858