Multiply with Carry Random Generator

Back in General Information we have two functions that define a random number generator. For this generator f1(...) is

temp = seed*mult + carry; // temp is 64 bits, all else is 32 bits unsigned
seed = temp % 2^32;
carry = temp >> 32;

or in 32-but 80x86 assembly

mov eax,[ebx] ;<--seed
mul mult ;mult = 3373259949
add eax,[ebx+4] ;<--carry
adc edx,0
mov [ebx],eax ;-->seed
mov [ebx+4],edx ;-->carry

The magic constant, mult, has some special numeric properties involving prime numbers. Comments from the source code:

; Notes on the magic number: it is int(pi*2^30)+523.
; 523 is the smallest number I could add such that
; m=(mult*2^32)-1 and mm=(m-1)/2 are both primes.

The function, f2(...) is simply “return seed”.

Next Topic (xor/shift generator)
Previous topic
Return to index