Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9537739

Browse files
committed
Fix pgbench's getrand() function so that min and max have approximately
the same chance of being selected as do numbers between them. Problemnoted by Greg Stark; fix by Alexey Klyukin.
1 parentd9384a4 commit9537739

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

‎contrib/pgbench/pgbench.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.75 2007/12/11 02:31:49 tgl Exp $
2+
* $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.76 2008/03/10 01:23:04 tgl Exp $
33
*
44
* pgbench: a simple benchmark program for PostgreSQL
55
* written by Tatsuo Ishii
@@ -191,11 +191,15 @@ usage(void)
191191
fprintf(stderr,"(initialize mode): pgbench -i [-h hostname][-p port][-s scaling_factor] [-F fillfactor] [-U login][-d][dbname]\n");
192192
}
193193

194-
/* random number generator */
194+
/* random number generator: uniform distribution from min to max inclusive */
195195
staticint
196196
getrand(intmin,intmax)
197197
{
198-
returnmin+ (int) (((max-min)* (double)random()) /MAX_RANDOM_VALUE+0.5);
198+
/*
199+
* Odd coding is so that min and max have approximately the same chance of
200+
* being selected as do numbers between them.
201+
*/
202+
returnmin+ (int) (((max-min+1)* (double)random()) / (MAX_RANDOM_VALUE+1.0));
199203
}
200204

201205
/* call PQexec() and exit() on failure */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp