Tuesday, November 2, 2010

An additive four-tap random number generator

Based on the pentanomial primitive over GF(2):

x^64 + x^39 + x^21 + x^13 + 1


static uint32_t Q[64];
uint32_t lfg() {
static uint32_t i = 0;
return Q[++i & 63] += Q[(i - 39) & 63] + Q[(i - 21) & 63] + Q[(i - 13) & 63];
}


Period is 2^95. Passes L'Ecuyer's BigCrush test suite.

Fill Q up with nonzeros. Multiply can be used as the operation, in which case Q must be filled with numbers of the form 4k-1. The period will also be shorter, read more here.

No comments: