Skip site navigation (1) Skip section navigation (2)

Re: [HACKERS] random() function produces wrong range

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Swan <tswan(at)olemiss(dot)edu>
Cc: Malcolm Beattie <mbeattie(at)sable(dot)ox(dot)ac(dot)uk>, Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>, pgsql-hackers(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: [HACKERS] random() function produces wrong range
Date: 2000-08-03 14:56:30
Message-ID: 7985.965314590@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-hackers
Thomas Swan <tswan(at)olemiss(dot)edu> writes:
>> I suspect we have a good chance at getting burned no matter what we use
>> :-(.  But RAND_MAX is definitely the wrong thing.

> Is it possible to test (during configure phase) and then go from there... 
> or does it need to be the same for all platforms?

I thought about that last night.  We could do a configure test.  Since
it'd be probing random() results there'd be a small probability of
failure, but if we wire in an assumption that the max value must be
2^(15 + n*16)-1 for some n, ten or so probes would give us a failure
probability on the order of 2^-160, which ought to satisfy anyone.

However, in the absence of any hard evidence that there are platforms
where the value is different from 2^31-1, it's probably just a waste of
configuration cycles at the moment.

I suggest we add a config.h constant like

/* The local random() function yields values 0 .. MAX_RANDOM_VALUE */
#define MAX_RANDOM_VALUE  <2^31-1>

and use that in the code.  Then, if we ever find a platform where
random() does actually produce 64-bit results, it'll be time enough
to crank up a real configure test to set the value.

Comments?

			regards, tom lane

In response to

Responses

pgsql-hackers by date

Next:From: Roland RobertsDate: 2000-08-03 15:18:34
Subject: Re: [HACKERS] random() function produces wrong range
Previous:From: Tom LaneDate: 2000-08-03 14:40:24
Subject: Re: comparing rows

pgsql-general by date

Next:From: Tom LaneDate: 2000-08-03 15:07:56
Subject: Re: Functional indices with const params.
Previous:From: Guillaume PerréalDate: 2000-08-03 14:37:35
Subject: Re: Can't copy from file into table

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group