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

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: (view raw, whole thread or download thread mbox)
Lists: pgsql-generalpgsql-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;

Oh well.
Christopher Masto         Senior Network Monkey      NetMonger Communications
chris(at)netmonger(dot)net        info(at)netmonger(dot)net

Free yourself, free your machine, free the daemon --

In response to


pgsql-hackers by date

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

pgsql-general by date

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

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