Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YDEAX-0001oN-TB for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Jan 2015 15:23:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YDEAX-0000yc-24 for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Jan 2015 15:23:09 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YDEAV-0000yV-Tl for pgsql-bugs@postgresql.org; Mon, 19 Jan 2015 15:23:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YDEAS-00025a-Op for pgsql-bugs@postgresql.org; Mon, 19 Jan 2015 15:23:06 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t0JFMtuY025877; Mon, 19 Jan 2015 10:22:56 -0500 From: Tom Lane To: pgsql-004@personal.formauri.es cc: pgsql-bugs@postgresql.org Subject: Re: BUG #12589: Poor randomness from random() with some seeds; poor resolution In-reply-to: <20150118175056.1983.60420@wrigleys.postgresql.org> References: <20150118175056.1983.60420@wrigleys.postgresql.org> Comments: In-reply-to pgsql-004@personal.formauri.es message dated "Sun, 18 Jan 2015 17:50:56 +0000" Date: Mon, 19 Jan 2015 10:22:55 -0500 Message-ID: <25876.1421680975@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 pgsql-004@personal.formauri.es writes: > [ setseed(1) behaves poorly on glibc platforms ] > PostgreSQL should probably use its own pseudo-random number generator and > not depend on the system's, This is not a bug; it's a feature request, and a rather poorly grounded one at that. If the user uses setseed(), he probably cares about getting the same sequence every time, and would not thank us for rolling in a different implementation with different behavior. (You could try griping to the glibc folk for providing a poor random() function on your platform, but I suspect they'd give largely the same answer.) Having said that, I think that most of your problem here stems from using an extremal value for the argument of setseed(). I get saner-looking behavior wih a seed of 0 or 0.1, or even 0.999999. We could possibly redefine setseed to take a range of -1 < x < 1 rather than -1 <= x <= 1, although that might break things unnecessarily for users on other platforms where srandom() doesn't have this odd corner case. regards, tom lane PS: also, if you have need of something better than random(), you could consider using pgcrypto's random number generator, or writing your own as an extension. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs