Silly bug in pgbench's random number generator - Mailing list pgsql-patches

From Gregory Stark
Subject Silly bug in pgbench's random number generator
Date
Msg-id 87fy4uv5qz.fsf@oxford.xeocode.com
Whole thread Raw
Responses Re: Silly bug in pgbench's random number generator
Re: Silly bug in pgbench's random number generator
List pgsql-patches
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


pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Concurrent psql patch
Next
From: Alexey Klyukin
Date:
Subject: Re: Silly bug in pgbench's random number generator