On Tue, 1 Aug 2000, Tom Lane wrote:
> The comment in the random() function indicates that its author thought
> it'd produce output in the range 0..1, which seems like a pretty
> reasonable definition:
>
> /* result 0.0-1.0 */
> result = ((double) random()) / RAND_MAX;
>
> Unfortunately, at least on my box, it produces no such thing. random()
> actually yields values in the range 0..2^31-1 --- while RAND_MAX is
> only 32767, because it applies to the rand() function not random().
> I would like to propose changing the code to
>
> /* result 0.0-1.0 */
> result = ((double) random()) / INT_MAX;
>
> (and making the corresponding change in setseed()). But I wonder if
> anyone out there has applications that depend on the current behavior.
Actually, on my machines, both man pages for rand() and random() say
they return values between 0 and RAND_MAX (whether that's true or not
is another matter). In my case RAND_MAX==INT_MAX so the change wouldn't
be a problem, but it might be problematic on some of the 64 bit machines.