svn commit: r279349 - head/sys/kern

Andrew Turner andrew at fubar.geek.nz
Fri Feb 27 08:23:10 UTC 2015


On Fri, 27 Feb 2015 02:56:59 +0000 (UTC)
Warner Losh <imp at FreeBSD.org> wrote:
...
>  /*
> + * We need some randomness. Implement the classic Linear Congruential
> + * generator X_{n+1}=(aX_n+c) mod m. These values are optimized for
> + * m = 2^32, a = 69069 and c = 5. This is signed so that we can get
> + * both positive and negative values from it by shifting the value
> + * right.
> + */
> +static int sched_random() 
> +{
> +        int rnd, *rndptr;
> +        rndptr = DPCPU_PTR(randomval);
> +        rnd = *rndptr * 69069 + 5;
> +        *rndptr = rnd;
> +        return(rnd);
> +} 

Didn't we recently have issues with signed integer overflow being
undefined? Even though we worked around it with a compiler flag it
would be better to not rely on undefined behaviour in the first place.

Andrew


More information about the svn-src-all mailing list