Re: random() function produces wrong range

From: Christopher Masto <chris(at)netmonger(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, roberts(at)panix(dot)com
Cc: Thomas Swan <tswan(at)olemiss(dot)edu>, 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: random() function produces wrong range
Date: 2000-08-04 18:28:28
Message-ID: 20000804142828.B18784@netmonger.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Thu, Aug 03, 2000 at 11:45:39AM -0400, Tom Lane wrote:
> Actually the odds are far better than that. If the range is 2^31-1
> then only about 2^-16th of the outputs should be less than 2^15.
> So ten probes gives you a failure probability of about 2^-160 not
> 2^-10.

It occurs to me that Perl has to provide a portable rand function, so
I looked at how its Configure script works. It's pretty much what
you've been discussing. First it checks for a couple of possible
random functions (preferring drand48(), then random(), then bitching
and using rand()).

int main()
{
register int i;
register unsigned long tmp;
register unsigned long max = 0L;

for (i = 1000; i; i--) {
tmp = (unsigned long) $randfunc();
if (tmp > max) max = tmp;
}
for (i = 0; max; i++)
max /= 2;
printf("%d\n",i);
}

Oh well.
--
Christopher Masto Senior Network Monkey NetMonger Communications
chris(at)netmonger(dot)net info(at)netmonger(dot)net http://www.netmonger.net

Free yourself, free your machine, free the daemon -- http://www.freebsd.org/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Philip Hallstrom 2000-08-04 18:30:14 Re: Need for rebuilding index after many deletions?
Previous Message Jeffrey A. Rhines 2000-08-04 17:51:14 Re: Need for rebuilding index after many deletions?

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Swan 2000-08-04 20:01:20 Differences between int8 and int4 as pkeys and fkeys
Previous Message Christopher Masto 2000-08-04 18:08:18 Re: comparing rows