Re: Silly bug in pgbench's random number generator

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alexey Klyukin <alexk(at)commandprompt(dot)com>
Cc: Gregory Stark <stark(at)enterprisedb(dot)com>, pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: Silly bug in pgbench's random number generator
Date: 2008-03-10 01:23:46
Message-ID: 17417.1205112226@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-patches

Alexey Klyukin <alexk(at)commandprompt(dot)com> writes:
> Gregory Stark wrote:
>> pgbench's random number generator was only generating the first and last value
>> in the specified range half as often as other values in the range.

> I think this line should be altered this way:
> return min + (int) (((max - min + 1) * (double) random()) / (MAX_RANDOM_VALUE + 1.0));
> eliminating the result of max + 1 in a corner case when random() equals to
> MAX_RANDOM_VALUE.

Yeah, that looks more correct. Applied.

regards, tom lane

In response to

Browse pgsql-patches by date

  From Date Subject
Next Message Tom Lane 2008-03-10 02:07:41 Re: Reduce the size of PageFreeSpaceInfo on 64bit platform
Previous Message Heikki Linnakangas 2008-03-08 18:17:26 Re: CopyReadAttributesCSV optimization