Re: random() function produces wrong range - Mailing list pgsql-hackers

From Roland Roberts
Subject Re: random() function produces wrong range
Date
Msg-id m21z061igl.fsf@tycho.rlent.pnet
Whole thread Raw
In response to random() function produces wrong range  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [GENERAL] Re: random() function produces wrong range  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
-----BEGIN PGP SIGNED MESSAGE-----

>>>>> "Thomas" == Thomas Swan <tswan@olemiss.edu> writes:

    Thomas> Is it possible to test (during configure phase) and then
    Thomas> go from there...  or does it need to be the same for all
    Thomas> platforms?

You should be able to test, but it is, of course, a statistical test.
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.  If those
odds aren't good enough, generate more.

roland
- --
               PGP Key ID: 66 BC 3B CD
Roland B. Roberts, PhD                    Unix Software Solutions
roberts@panix.com                      76-15 113th Street, Apt 3B
rbroberts@acm.org                          Forest Hills, NY 11375

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3a
Charset: noconv
Comment: Processed by Mailcrypt 3.5.4, an Emacs/PGP interface

iQCVAwUBOYmNSeoW38lmvDvNAQHFegQAlexEvaG0t+1H0IkPWikbdMUIck1fE0DI
rfcGi1M/SQ6K9Hmvi1HB/SVEU4DKGaHDoqlU7ei78OgOzchbsLL5cqAJNIsKv5QJ
F4u/A0Fg7yuyRZ3/CNCo0+nTwhyDANktMw78AM5ssHCs75UxC+vHWibHHBmXJzrF
8WD2LyjPSNI=
=dR25
-----END PGP SIGNATURE-----

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: random() function produces wrong range
Next
From: Malcolm Beattie
Date:
Subject: Re: random() function produces wrong range