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

From: Tom Lane roberts(at)panix(dot)com Thomas Swan , Malcolm Beattie , Thomas Lockhart , pgsql-hackers(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org Re: Re: [HACKERS] random() function produces wrong range 2000-08-03 15:45:39 8198.965317539@sss.pgh.pa.us (view raw or whole thread) 2000-08-01 16:02:36 from Tom Lane  2000-08-01 17:46:46 from Stephan Szabo   2000-08-01 18:23:38 from Tom Lane    2000-08-01 20:20:44 from Stephan Szabo     2000-08-01 20:40:33 from Dave Smith    2000-08-01 22:26:36 from "Mike Sears"     2000-08-01 18:33:18 from Tom Lane  2000-08-02 06:10:34 from Thomas Lockhart   2000-08-02 14:07:48 from Tom Lane    2000-08-02 14:21:45 from Malcolm Beattie     2000-08-02 20:36:20 from Tom Lane      2000-08-03 03:23:07 from Thomas Swan       2000-08-03 14:56:30 from Tom Lane        2000-08-03 15:27:56 from Malcolm Beattie       2000-08-03 15:18:34 from Roland Roberts        2000-08-03 15:45:39 from Tom Lane         2000-08-03 17:36:01 from Roland Roberts         2000-08-04 18:28:28 from Christopher Masto          2000-08-04 20:01:20 from Thomas Swan           2000-08-05 02:28:32 from Thomas Lockhart    2000-08-03 19:43:51 from Chris Jones 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

```

### pgsql-hackers by date

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

### pgsql-general by date

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