Skip site navigation (1) Skip section navigation (2)

Re: Silly bug in pgbench's random number generator

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: pgsql-patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: Silly bug in pgbench's random number generator
Date: 2007-07-17 04:50:23
Message-ID: 200707170450.l6H4oNW04933@momjian.us (view raw or flat)
Thread:
Lists: pgsql-patches
This has been saved for the 8.4 release:

	http://momjian.postgresql.org/cgi-bin/pgpatches_hold

---------------------------------------------------------------------------

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. Not that it
> actually matters but it may as well do what it claims. This line has a pretty
> long and sordid history with various people tweaking it one way and another.
> 
> cvs diff: Diffing contrib/pgbench
> Index: contrib/pgbench/pgbench.c
> ===================================================================
> RCS file: /home/stark/src/REPOSITORY/pgsql/contrib/pgbench/pgbench.c,v
> retrieving revision 1.66
> diff -u -r1.66 pgbench.c
> --- contrib/pgbench/pgbench.c	24 May 2007 18:54:10 -0000	1.66
> +++ contrib/pgbench/pgbench.c	14 Jun 2007 16:22:19 -0000
> @@ -191,7 +191,7 @@
>  static int
>  getrand(int min, int max)
>  {
> -	return min + (int) (((max - min) * (double) random()) / MAX_RANDOM_VALUE + 0.5);
> +	return min + (int) (((max - min + 1) * (double) random()) / MAX_RANDOM_VALUE);
>  }
>  
>  /* call PQexec() and exit() on failure */
> 
> 
> -- 
>   Gregory Stark
>   EnterpriseDB          http://www.enterprisedb.com
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
> 
>                 http://www.postgresql.org/about/donate

-- 
  Bruce Momjian  <bruce(at)momjian(dot)us>          http://momjian.us
  EnterpriseDB                               http://www.enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +

In response to

Responses

pgsql-patches by date

Next:From: Gregory StarkDate: 2007-07-17 05:03:29
Subject: Re: Silly bug in pgbench's random number generator
Previous:From: Bruce MomjianDate: 2007-07-17 04:11:59
Subject: Re: Patch for recent PITR bug

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group