Multiply With Carry

This algorithm generates a random number.



									/*****Please include following header files*****/
// stdint.h
/***********************************************/

unsigned int Q[4096];
unsigned int c = 362436;
unsigned int i = 4095;

unsigned int MultiplyWithCarry() {
	uint64_t t, a = 18782;
	unsigned int x, r = 0xfffffffe;

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

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

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


Example

									unsigned int value = MultiplyWithCarry();
								


Output

									4294604858