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
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-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

Browse pgsql-general by date

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

Browse pgsql-hackers by date

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