1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-27 23:21:58 +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

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.67 2000/08/01 18:29:35 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/float.c,v 1.68 2000/08/07 00:51:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -1315,7 +1315,7 @@ drandom(PG_FUNCTION_ARGS)
float8 result;
/* result 0.0-1.0 */
result = ((double) random()) / RAND_MAX;
result = ((double) random()) / ((double) MAX_RANDOM_VALUE);
PG_RETURN_FLOAT8(result);
}
@ -1328,7 +1328,7 @@ Datum
setseed(PG_FUNCTION_ARGS)
{
float8 seed = PG_GETARG_FLOAT8(0);
int iseed = (seed * RAND_MAX);
int iseed = (int) (seed * MAX_RANDOM_VALUE);
srandom((unsigned int) iseed);