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

From: Roland Roberts <roberts(at)panix(dot)com>
To: Thomas Swan <tswan(at)olemiss(dot)edu>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, 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: [HACKERS] random() function produces wrong range
Date: 2000-08-03 15:18:34
Message-ID: m21z061igl.fsf@tycho.rlent.pnet
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

-----BEGIN PGP SIGNED MESSAGE-----

>>>>> "Thomas" == Thomas Swan <tswan(at)olemiss(dot)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(at)panix(dot)com 76-15 113th Street, Apt 3B
rbroberts(at)acm(dot)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-----

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Malcolm Beattie 2000-08-03 15:27:56 Re: random() function produces wrong range
Previous Message Tom Lane 2000-08-03 15:11:48 Re: Unions in views

Browse pgsql-hackers by date

  From Date Subject
Next Message Malcolm Beattie 2000-08-03 15:27:56 Re: random() function produces wrong range
Previous Message Tom Lane 2000-08-03 14:56:30 Re: [HACKERS] random() function produces wrong range