[riot-notifications] [RIOT] add mersene twister (#168)

René Kijewski notifications at github.com
Wed Aug 21 23:11:51 CEST 2013


> +    if (mti >= N) { /* generate N words at one time */
> +        int kk;
> +
> +        if (mti == N + 1) /* if init_genrand() has not been called, */
> +            init_genrand(5489UL); /* a default initial seed is used */
> +
> +        for (kk = 0; kk < N - M; kk++) {
> +            y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
> +            mt[kk] = mt[kk + M] ^ (y >> 1) ^ mag01[y & 0x1UL];
> +        }
> +        for (; kk < N - 1; kk++) {
> +            y = (mt[kk] & UPPER_MASK) | (mt[kk + 1] & LOWER_MASK);
> +            mt[kk] = mt[kk + (M - N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
> +        }
> +        y = (mt[N - 1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
> +        mt[N - 1] = mt[M - 1] ^ (y >> 1) ^ mag01[y & 0x1UL];

The part after the XOR is ugly. Better use:

    mt[N - 1] ^= y >> 1;
    if (y & 1) {
        mt[N - 1] ^= MATRIX_A;
    }

and eliminate `mag01`.

---
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/168/files#r5909267
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20130821/bb698caf/attachment.html>


More information about the notifications mailing list