Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VYaZ1-0006IQ-Od for pgsql-bugs@arkaria.postgresql.org; Tue, 22 Oct 2013 11:55:55 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VYaZ0-0006YM-E5 for pgsql-bugs@arkaria.postgresql.org; Tue, 22 Oct 2013 11:55:54 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VYaYy-0006YB-Cv for pgsql-bugs@postgresql.org; Tue, 22 Oct 2013 11:55:52 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VYaYs-0007MI-SW for pgsql-bugs@postgresql.org; Tue, 22 Oct 2013 11:55:50 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9MBtjet010587 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 22 Oct 2013 07:55:45 -0400 Received: from hhorak-t510.usersys.redhat.com (unused-4-233.brq.redhat.com [10.34.4.233]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r9MBtiYm025784; Tue, 22 Oct 2013 07:55:44 -0400 Message-ID: <526667BF.3040601@redhat.com> Date: Tue, 22 Oct 2013 13:55:43 +0200 From: Honza Horak User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130923 Thunderbird/17.0.9 MIME-Version: 1.0 To: Heikki Linnakangas CC: pgsql-bugs@postgresql.org Subject: Re: random() generates collisions too early References: <5261219D.3060205@redhat.com> <526537ED.2010607@vmware.com> In-Reply-To: <526537ED.2010607@vmware.com> Content-Type: multipart/mixed; boundary="------------070700020306000508060109" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-Pg-Spam-Score: -7.3 (-------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------070700020306000508060109 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------070700020306000508060109 Content-Type: text/x-patch; name="random-doc.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="random-doc.patch" 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 @@ random() dp - random value in the range 0.0 <= x < 1.0 + 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) random() --------------070700020306000508060109 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --------------070700020306000508060109--