*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.90 2005/11/22 18:17:08 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.91 2006/02/03 12:45:47 momjian Exp $
*
*-------------------------------------------------------------------------
*/
return numrows;
}
-/* Select a random value R uniformly distributed in 0 < R < 1 */
+/* Select a random value R uniformly distributed in (0 - 1) */
static double
random_fract(void)
{
- long z;
-
- /* random() can produce endpoint values, try again if so */
- do
- {
- z = random();
- } while (z <= 0 || z >= MAX_RANDOM_VALUE);
- return (double) z / (double) MAX_RANDOM_VALUE;
+ return ((double) random() + 1) / ((double) MAX_RANDOM_VALUE + 2);
}
/*
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.41 2005/11/22 18:17:21 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.42 2006/02/03 12:45:47 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/* increase delay by a random fraction between 1X and 2X */
cur_delay += (int) (cur_delay *
- (((double) random()) / ((double) MAX_RANDOM_VALUE)) + 0.5);
+ ((double) random() / (double) MAX_RANDOM_VALUE) + 0.5);
/* wrap back to minimum delay when max is exceeded */
if (cur_delay > MAX_DELAY_MSEC)
cur_delay = MIN_DELAY_MSEC;
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.119 2005/12/02 02:49:11 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.120 2006/02/03 12:45:47 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{
float8 result;
- /* result 0.0-1.0 */
- result = ((double) random()) / ((double) MAX_RANDOM_VALUE);
+ /* result [0.0 - 1.0) */
+ result = (double) random() / ((double) MAX_RANDOM_VALUE + 1);
PG_RETURN_FLOAT8(result);
}
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/optimizer/geqo_random.h,v 1.16 2004/12/31 22:03:36 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/optimizer/geqo_random.h,v 1.17 2006/02/03 12:45:47 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/* geqo_rand returns a random float value between 0 and 1 inclusive */
-#define geqo_rand() (((double) random()) / ((double) MAX_RANDOM_VALUE))
+#define geqo_rand() ((double) random() / (double) MAX_RANDOM_VALUE)
/* geqo_randint returns integer value between lower and upper inclusive */