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 1lzR4i-0005MO-S6 for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Jul 2021 21:51:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lzR4g-0006po-OG for pgsql-hackers@arkaria.postgresql.org; Fri, 02 Jul 2021 21:51:50 +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 1lzR4g-0006pf-GU for pgsql-hackers@lists.postgresql.org; Fri, 02 Jul 2021 21:51:50 +0000 Received: from sfr-1.cri.mines-paristech.fr ([77.158.180.225] helo=smtp.cri.ensmp.fr) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lzR4Z-0007HQ-QU for pgsql-hackers@lists.postgresql.org; Fri, 02 Jul 2021 21:51:50 +0000 Received: from pseudo (185.141.6.84.rev.sfr.net [84.6.141.185]) by smtp.cri.ensmp.fr (Postfix) with ESMTPSA id 4D0FEC019D; Fri, 2 Jul 2021 23:53:42 +0200 (CEST) Date: Fri, 2 Jul 2021 23:51:42 +0200 (CEST) From: Fabien COELHO X-X-Sender: fabien@pseudo To: Dean Rasheed cc: Tom Lane , Aleksander Alekseev , PostgreSQL Developers Subject: Re: rand48 replacement In-Reply-To: Message-ID: References: <43a6e30b-542f-671a-e7bb-b7f78cf90e8c@enterprisedb.com> <699567.1625156441@sss.pgh.pa.us> <746421.1625164869@sss.pgh.pa.us> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Dean, > It may be true that the bias is of the same magnitude as FP multiply, > but it is not of the same nature. With FP multiply, the > more-likely-to-be-chosen values are more-or-less evenly distributed > across the range, whereas modulo concentrates them all at one end, > making it more likely to bias test results. Yes, that is true. > It's worth paying attention to how other languages/libraries implement > this, and basically no one chooses the modulo method, which ought to > raise alarm bells. Of the biased methods, it has the worst kind of > bias and the worst performance. Hmmm. That is not exactly how I interpreted the figures in the blog. > If a biased method is OK, then the biased integer multiply method > seems to be the clear winner. This requires the high part of a > 64x64-bit product, which is trivial if 128-bit integers are available, > but would need a little more work otherwise. There's some code in > common/d2s that might be suitable. And yes, modulo is expensive. If we allow 128 bits integers operations, I would not choose this RNPG in the first place, I'd take PCG with a 128 bits state. That does not change the discussion about bias, though. > Most other implementations tend to use an unbiased method though, and I > think it's worth doing the same. It might be a bit slower, or even > faster depending on implementation and platform, but in the context of > the DB as a whole, I don't think a few extra cycles matters either way. Ok ok ok, I surrender! > The method recommended at the very end of that blog seems to be pretty > good all round, but any of the other commonly used unbiased methods > would probably be OK too. That does not address my other issues with the proposed methods, in particular the fact that the generated sequence is less deterministic, but I think I have a simple way around that. I'm hesitating to skip to the the bitmask method, and give up performance uniformity. I'll try to come up with something over the week-end, and also address Tom's comments in passing. -- Fabien.