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

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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: 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: Re: [HACKERS] random() function produces wrong range
Date: 2000-08-03 15:45:39
Message-ID: 8198.965317539@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-hackers
Roland Roberts <roberts(at)panix(dot)com> writes:
> Call random() several times and test the maximum value against your
> thresholds of 2^15 and 2^31.  If random() is generating values in the
> range 1:2^31-1, you would expect half of your values to be greater
> than 2^15-1; more importantly, if you generate, say, 10 values, you
> expect only a 1:1024 chance that they are all below 2^15.

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.

Generalizing, you could tell the difference between widths of 31,
47, or 63 bits with the same level of reliability.

			regards, tom lane

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2000-08-03 16:20:50
Subject: bit/varbit stuff
Previous:From: Malcolm BeattieDate: 2000-08-03 15:27:56
Subject: Re: random() function produces wrong range

pgsql-general by date

Next:From: luc00Date: 2000-08-03 16:07:55
Subject: OFF topic : does anybody know free hosting with PgSQL & PHP
Previous:From: Federico Sevilla IIIDate: 2000-08-03 15:37:31
Subject: Re: Unions in views

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