Re: random() function produces wrong range

From: Malcolm Beattie <mbeattie(at)sable(dot)ox(dot)ac(dot)uk>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Thomas Swan <tswan(at)olemiss(dot)edu>, Thomas Lockhart <lockhart(at)alumni(dot)caltech(dot)edu>, pgsql-hackers(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: random() function produces wrong range
Date: 2000-08-03 15:27:56
Message-ID: 20000803162756.B715@sable.ox.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Tom Lane writes:
> 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?

If any platform *does* produced 64-bit results, it won't be compliant
with SUSv2 which states explicitly that the resulting range is up to
2^31-1. Since most portability problems are with older platforms which
haven't caught up, I'd be hopeful that any new 64-bit-int platforms
would get it right from the outset. Maybe I'm being over-optimistic :-)

--Malcolm

--
Malcolm Beattie <mbeattie(at)sable(dot)ox(dot)ac(dot)uk> I am looking for a Linux (and
Unix Systems Programmer maybe Apache/mod_perl) job/contract
Oxford University Computing Services http://users.ox.ac.uk/~mbeattie/cv.html

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Federico Sevilla III 2000-08-03 15:37:31 Re: Unions in views
Previous Message Roland Roberts 2000-08-03 15:18:34 Re: [HACKERS] random() function produces wrong range

Browse pgsql-hackers by date

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