pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Honza Horak <hhorak@redhat.com>
To: Heikki Linnakangas <hlinnakangas@vmware.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: random() generates collisions too early
Date: Tue, 22 Oct 2013 13:55:43 +0200
Message-ID: <526667BF.3040601@redhat.com> (raw)
In-Reply-To: <526537ED.2010607@vmware.com>
References: <5261219D.3060205@redhat.com>
	<526537ED.2010607@vmware.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

On 10/21/2013 04:19 PM, Heikki Linnakangas wrote:
> On 18.10.2013 14:55, Honza Horak wrote:
>> On 10/18/2013 02:10 AM, Noah Misch wrote:
>>  > sudo sysctl -w kernel.pid_max=2048
>>  > psql -c 'create unlogged table samp(c float8)'
>>  > for n in `seq 1 200000`; do psql -qc 'insert into samp values
>> (random())'; done
>>  >
>>  > The results covered only 181383 distinct values, and 68 values
>> repeated four
>>  > or five times each. We should at least consider using a
>> higher-entropy seed.
>>
>> As I was told this is not taken as a security issue, since random() is
>> not considered as a CSPRNG in any case, but as Noah said, we should
>> probably try to make it a bit better.
>
> Interesting. PostgreSQL's random() function just calls the underlying
> libc random() function. I assume you tested this on with Linux and glibc.
>
>> Also, I'd suggest to state explicitly in the doc, that random()
>> shouldn't be taken as CSPRNG, since I can imagine people blindly
>> believing that random() can be good enough for such use cases, just
>> because they see how many possible values they get from double-precision
>> type:
>> http://www.postgresql.org/docs/9.3/static/functions-math.html
>
> Yeah, that seems like a good idea. A patch would be welcome.

I don't think we need to tell some long stories here, so what about this 
one:
"pseudo-random value in the range 0.0 < x < 1.0 (characteristic of 
randomness depends on the system implementation and is usually limited, 
thus not considered as a CSPRNG in any case)"

Corresponding patch of doc is attached.

Regards,
Honza

-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

Attachments:

random-doc.patch (text/x-patch, 670B) download diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index e397386..6d9d531 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -836,7 +836,9 @@ <literal><function>random()</function></literal> </entry> <entry><type>dp</type></entry> - <entry>random value in the range 0.0 &lt;= x &lt; 1.0</entry> + <entry>pseudo-random value in the range 0.0 &lt;= x &lt; 1.0 + (characteristic of randomness depends on the system implementation + and is usually limited, thus not considered as a CSPRNG in any case)</entry> <entry><literal>random()</literal></entry> <entry></entry> </row>

view thread (11+ messages)  latest in thread

Message-ID: <526667BF.3040601@redhat.com>
Permalink:  ../526667BF.3040601@redhat.com/
Also on:    postgresql.org/message-id/526667BF.3040601@redhat.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: hhorak@redhat.com, hlinnakangas@vmware.com
  Subject: Re: random() generates collisions too early
  In-Reply-To: <526667BF.3040601@redhat.com>
  References: <5261219D.3060205@redhat.com> <526537ED.2010607@vmware.com> <526667BF.3040601@redhat.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox