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

René Kijewski notifications at github.com
Thu Aug 22 14:30:28 CEST 2013


> +        i++;
> +        if (i >= N) {
> +            mt[0] = mt[N - 1];
> +            i = 1;
> +        }
> +    }
> +
> +    mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
> +}
> +
> +/**
> + * generates a random number on [0,0xffffffff]-interval
> + */
> +uint32_t genrand_int32(void)
> +{
> +    uint32_t y;

Am Thu, 22 Aug 2013 04:16:27 -0700
schrieb Oleg Hahm <notifications at github.com>:

> > +        i++;
> > +        if (i >= N) {
> > +            mt[0] = mt[N - 1];
> > +            i = 1;
> > +        }
> > +    }
> > +
> > +    mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
> > +}
> > +
> > +/**
> > + * generates a random number on [0,0xffffffff]-interval
> > + */
> > +uint32_t genrand_int32(void)
> > +{
> > +    uint32_t y;
> 
> What's wrong with ANSI style declarations? I personally prefer them.

IMHO the problem with ANSI style declarations is that

1. often you have to scroll up a page or two to find the declaration ("Was `i` signed or unsigned, again?").
2. they suggest wrong relations between variables. In this very example `y` was used in three places, merely related by its name.
3. generally speaking I'd prefer the tightest visibility of variables/identifiers possible. E.g. when `i` is your index variable for this loop, then declare it in the loop initialization and not someplace else.
4. people seldom use them right. In ANSI you may declare variables in the beginning of every scope (e.g. a loop body), not only at the beginning of the function body.
5. `int i; foo(bar); i = 42; …` just looks wrong.
6. concluding: using C99 style variable declarations it is much easier at first glance to tell the meaning of a variable.

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


More information about the notifications mailing list