1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-27 00:12:01 +03:00

Clean up bogosities in use of random(3) and srandom(3) --- do not assume

that RAND_MAX applies to them, since it doesn't.  Instead add a
config.h parameter MAX_RANDOM_VALUE.  This is currently set at 2^31-1
but could be auto-configured if that ever proves necessary.  Also fix
some outright bugs like calling srand() where srandom() is appropriate.
This commit is contained in:
Tom Lane
2000-08-07 00:51:42 +00:00
parent 259489bab7
commit 9426047021
8 changed files with 47 additions and 25 deletions

View File

@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: geqo_random.h,v 1.6 2000/01/26 05:58:20 momjian Exp $
* $Id: geqo_random.h,v 1.7 2000/08/07 00:51:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -26,13 +26,13 @@
#include <math.h>
#define GEQOMASK 2147483647
/* geqo_rand returns a random float value between 0 and 1 inclusive */
#define geqo_rand() ((double)random()/GEQOMASK)
#define geqo_rand() (((double) random()) / ((double) MAX_RANDOM_VALUE))
/* geqo_randint returns integer value
between lower and upper inclusive */
/* geqo_randint returns integer value between lower and upper inclusive */
#define geqo_randint(upper,lower) ( (int) floor( geqo_rand()*((upper-lower)+0.999999) ) + lower )
#define geqo_randint(upper,lower) \
( (int) floor( geqo_rand()*(((upper)-(lower))+0.999999) ) + (lower) )
#endif /* GEQO_RANDOM_H */