From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | andrew(at)supernews(dot)com, PostgreSQL-patches <pgsql-patches(at)postgresql(dot)org> |
Subject: | Re: [HACKERS] Bug: random() can return 1.0 |
Date: | 2006-02-01 17:23:54 |
Message-ID: | 200602011723.k11HNsd29134@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers pgsql-patches |
Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)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);
Here is a patch that makes this change, and cleans up other
MAX_RANDOM_VALUE uses.
--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
Attachment | Content-Type | Size |
---|---|---|
unknown_filename | text/plain | 3.5 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2006-02-01 17:29:05 | Re: [HACKERS] autovacuum |
Previous Message | Chris Browne | 2006-02-01 17:14:41 | Re: autovacuum |
From | Date | Subject | |
---|---|---|---|
Next Message | Bruce Momjian | 2006-02-01 17:45:11 | Re: TODO-Item: B-tree fillfactor control |
Previous Message | Bruce Momjian | 2006-02-01 15:24:11 | test, please ignore |