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

On 22.10.2013 14:55, Honza Horak wrote:
> On 10/21/2013 04:19 PM, Heikki Linnakangas wrote:
>> On 18.10.2013 14:55, Honza Horak wrote:
>>> 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)"

I had to look up what CSPRNG stands for, so we probably should spell it 
out. Also not sure what it means for the characteristic of the 
randomness to be limited. How about something like:

> random value in the range 0.0 <= x < 1.0 (the characteristics of the
> returned values depends on the system implementation. This function
> is not suitable for cryptographic applications; use pgcrypto
> instead.)

Or perhaps it would be even better to move random() and setseed to a 
separate table. They are somewhat different from the rest of the 
functions listed in the table of Mathematical Functions, and it would be 
nice to list them together; currently the round() functions fall between 
them in the alphabetically ordered table. What do you think of the attached?

- Heikki

-- 
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-1.patch (text/x-diff, 3.0K) download diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index e397386..b53145a 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -831,19 +831,6 @@ <row> <entry> <indexterm> - <primary>random</primary> - </indexterm> - <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><literal>random()</literal></entry> - <entry></entry> - </row> - - <row> - <entry> - <indexterm> <primary>round</primary> </indexterm> <literal><function>round(<type>dp</type> or <type>numeric</type>)</function></literal> @@ -865,20 +852,6 @@ <row> <entry> <indexterm> - <primary>setseed</primary> - </indexterm> - <literal><function>setseed(<type>dp</type>)</function></literal> - </entry> - <entry><type>void</type></entry> - <entry>set seed for subsequent <literal>random()</literal> calls (value between -1.0 and - 1.0, inclusive)</entry> - <entry><literal>setseed(0.54823)</literal></entry> - <entry></entry> - </row> - - <row> - <entry> - <indexterm> <primary>sign</primary> </indexterm> <literal><function>sign(<type>dp</type> or <type>numeric</type>)</function></literal> @@ -952,6 +925,56 @@ </table> <para> + <xref linkend="functions-math-random-table"> shows functions for + generating random numbers. + </para> + + <table id="functions-math-random-table"> + <title>Random Functions</title> + + <tgroup cols="2"> + <thead> + <row> + <entry>Function</entry> + <entry>Return Type</entry> + <entry>Description</entry> + </row> + </thead> + <tbody> + <row> + <entry> + <indexterm> + <primary>random</primary> + </indexterm> + <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> + </row> + + <row> + <entry> + <indexterm> + <primary>setseed</primary> + </indexterm> + <literal><function>setseed(<type>dp</type>)</function></literal> + </entry> + <entry><type>void</type></entry> + <entry>set seed for subsequent <literal>random()</literal> calls (value between -1.0 and + 1.0, inclusive)</entry> + </row> + </tbody> + </tgroup> + </table> + + <para> + The characteristics of the values returned by + <literal><function>random()</function></literal> depends + on the system implementation. It is not suitable for cryptographic + applications; see <xref linkend="pgcrypto"> module for an alternative. + </para> + + <para> Finally, <xref linkend="functions-math-trig-table"> shows the available trigonometric functions. All trigonometric functions take arguments and return values of type <type>double

view thread (11+ messages)  latest in thread

Message-ID: <5267AC01.1030203@vmware.com>
Permalink:  ../5267AC01.1030203@vmware.com/
Also on:    postgresql.org/message-id/5267AC01.1030203@vmware.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: hlinnakangas@vmware.com, hhorak@redhat.com
  Subject: Re: random() generates collisions too early
  In-Reply-To: <5267AC01.1030203@vmware.com>
  References: <5261219D.3060205@redhat.com> <526537ED.2010607@vmware.com> <526667BF.3040601@redhat.com> <5267AC01.1030203@vmware.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