Re: PG & random() strangeness - Mailing list pgsql-general

From Sergey E. Koposov
Subject Re: PG & random() strangeness
Date
Msg-id alpine.LRH.2.00.1005042013441.27603@lnfm1.sai.msu.ru
Whole thread Raw
In response to Re: PG & random() strangeness  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: PG & random() strangeness  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: PG & random() strangeness  (Marc Schablewski <ms@clickware.de>)
List pgsql-general
On Tue, 4 May 2010, Tom Lane wrote:

> "Sergey E. Koposov" <math@sai.msu.ru> writes:
>> So among 10^5 random numbers there are already 3 collisions. Which doesn't
>> seem right for the function which generate randoms of double precision
>
> The underlying random() function only generates 31-bit integers, so

Okay, the fact that they are 31bit, instead of 64 bit seems to be part of
the issue, I agree. I forgot about that, and that should obviously highly
increase the number of collisions. (it maybe worthwile to add the
31bittness of random to the docs, because the fact that it returns double
may be confusing (as it was to me)).

>> It is also interesting that in the table tmpx1 (if I actually output the
>> values using select id from tmpx1) I do not see equal numbers at all but I see
>> for example two values which are close to each other:
>>     0.511193082667887
>>     0.511194097343832
>
>> First it seems strange that they have been merged into one group by "groupby".
>
> They aren't; or at least you've not provided any evidence that they were.

I think I did, since:

## select id ,count(*) from tmpx group by (id) having count(*)>1;
          id         | count
--------------------+-------
   0.519465064629912 |     2
  0.0100625408813357 |     2
   0.394671014975756 |     2
(3 rows)

and
## select id from tmpx where id > 0.51119 and id < 0.51120;
         id
-------------------
  0.511193082667887
  0.511194097343832
(2 rows)


Regards,
     S.

*******************************************************************
Sergey E. Koposov, PhD
Institute for Astronomy, University of Cambridge, UK
Web: http://lnfm1.sai.msu.ru/~math
E-mail: math@sai.msu.ru

pgsql-general by date:

Previous
From: Leif Biberg Kristensen
Date:
Subject: Re: GeSHi module for Postgresql?
Next
From: Vincenzo Romano
Date:
Subject: (psuedo) random serial for PK or at least UNIQUE NOT NULL?