amd64/81279: /usr/games/random returns every line

John Baldwin jhb at
Fri May 27 08:29:53 PDT 2005

On Thursday 19 May 2005 05:30 pm, Adriaan de Groot wrote:
> The following reply was made to PR amd64/81279; it has been noted by GNATS.
> From: Adriaan de Groot <groot at>
> To: bug-followup at, vivek at
> Cc:
> Subject: Re: amd64/81279: /usr/games/random returns every line
> Date: Thu, 19 May 2005 23:26:08 +0200
>  Problem is lines like
>          selected = (int)(denom * random() / LONG_MAX) == 0;
>  which cause the overflow. Replacing LONG_MAX with INT_MAX here fixes the
> bug. (The same replacement should probably be done in the other two places
> that LONG_MAX occurs, since the -e flag is similarly broken.)

I can't see how the overflow happens.  Oh.  From the manpage:

     The random() function uses a non-linear additive feedback random number
     generator employing a default table of size 31 long integers to return
     successive pseudo-random numbers in the range from 0 to (2**31)-1.  The
     period of this random number generator is very large, approximately

So I guess the real fix is to replace LONG_MAX with RAND_MAX?

John Baldwin <jhb at>  <><
"Power Users Use the Power to Serve"  =

More information about the freebsd-amd64 mailing list