Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mrWbL-0002rb-UA for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Nov 2021 02:41:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mrWbK-0003gY-3l for pgsql-hackers@arkaria.postgresql.org; Mon, 29 Nov 2021 02:41:06 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mrWbJ-0003gP-Qh for pgsql-hackers@lists.postgresql.org; Mon, 29 Nov 2021 02:41:05 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mrWbH-0001gL-PK for pgsql-hackers@lists.postgresql.org; Mon, 29 Nov 2021 02:41:05 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1AT2efRi1119726; Sun, 28 Nov 2021 21:40:43 -0500 From: Tom Lane To: Fabien COELHO cc: Aleksander Alekseev , Thomas Munro , PostgreSQL Developers Subject: Re: rand48 replacement In-reply-to: References: <3b12e2dea4c3c33665c33b40c95349ef@postgrespro.ru> <8904daa4a916b4990b11d7140e0ff81f@postgrespro.ru> <2520097.1632590602@sss.pgh.pa.us> <438984.1637951199@sss.pgh.pa.us> <600733.1638042551@sss.pgh.pa.us> Comments: In-reply-to Fabien COELHO message dated "Sun, 28 Nov 2021 10:26:57 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1119724.1638153641.1@sss.pgh.pa.us> Date: Sun, 28 Nov 2021 21:40:41 -0500 Message-ID: <1119725.1638153641@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Fabien COELHO writes: >> Good, but then you shouldn't write associated code as if that's still >> a problem, because you'll cause other people to think it's still a >> problem and write equally contorted code elsewhere. "v & 1" is a >> transparent way of producing a bool, while this code isn't. > Some Xoshiro-family generators have "linear artifacts in the low bits", > Although Xoroshiro128** is supposed to be immune, I thought better to keep > away from these, and I could not see why the last bit would be better than > any other bit, so taking the first looked okay to me at least. Meh. If we're going to trust the high bits more than the lower ones, we should do so consistently; it makes no sense to do that in one pg_prng.c function and not its siblings. Pushed with that change and some others, notably: * Rewrote a lot of the comments. * Refactored so that pg_strong_random() is not called from pg_prng.c. As it stood, that would result in pulling in OpenSSL in programs that have no need of it. (ldexp() still creates a dependency on libm, but I figured that was OK.) * Changed a number of call sites that were using modulo reduction to use pg_prng_uint64_range instead. Given the lengthy discussion we had, it seems silly not to apply the conclusion everywhere. regards, tom lane