Date: Fri, 27 Feb 2015 08:22:57 +0000 From: Andrew Turner <andrew@fubar.geek.nz> To: Warner Losh <imp@FreeBSD.org> Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r279349 - head/sys/kern Message-ID: <20150227082257.3fb1081c@bender.Home> In-Reply-To: <201502270256.t1R2uxnv085328@svn.freebsd.org> References: <201502270256.t1R2uxnv085328@svn.freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 27 Feb 2015 02:56:59 +0000 (UTC)
Warner Losh <imp@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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20150227082257.3fb1081c>
