Re: Bug: random() can return 1.0 - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Bug: random() can return 1.0
Date
Msg-id 10560.1137713169@sss.pgh.pa.us
Whole thread Raw
In response to Re: Bug: random() can return 1.0  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-hackers
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> Because random returns a double, I think it is very possible that we
> could return 1 due to rounding,

Not unless your machine has a "double" type with less than 32 bits of
precision, which seems pretty unlikely.  It'd be sufficient to do
/* result 0.0 <= x < 1.0 */result = ((double) random()) / ((double) MAX_RANDOM_VALUE + 1.0);

        regards, tom lane


pgsql-hackers by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Large Scale Aggregation (HashAgg Enhancement)
Next
From: Michael Fuhr
Date:
Subject: Re: un-vacuum?