pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Fabien COELHO <coelho@cri.ensmp.fr>
Cc: Aleksander Alekseev <aleksander@timescale.com>
Cc: Thomas Munro <thomas.munro@gmail.com>
Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Subject: Re: rand48 replacement
Date: Sun, 28 Nov 2021 21:40:41 -0500
Message-ID: <1119725.1638153641@sss.pgh.pa.us> (raw)
In-Reply-To: <alpine.DEB.2.22.394.2111280837520.223291@pseudo>
References: <alpine.DEB.2.22.394.2105241211230.165418@pseudo>
	<3b12e2dea4c3c33665c33b40c95349ef@postgrespro.ru>
	<alpine.DEB.2.22.394.2107060956180.3858351@pseudo>
	<8904daa4a916b4990b11d7140e0ff81f@postgrespro.ru>
	<alpine.DEB.2.22.394.2107072036140.4160419@pseudo>
	<CAJ7c6TOjfmtyBFZUzGLTSvSGydxUTjY67kn-FFrSUBgEpy7zrw@mail.gmail.com>
	<alpine.DEB.2.22.394.2109250938560.3216312@pseudo>
	<alpine.DEB.2.22.394.2109251643350.3216312@pseudo>
	<alpine.DEB.2.22.394.2109251824550.3216312@pseudo>
	<2520097.1632590602@sss.pgh.pa.us>
	<alpine.DEB.2.22.394.2109251929180.3216312@pseudo>
	<alpine.DEB.2.22.394.2109301015090.1807498@pseudo>
	<CA+hUKGL_R4Aujuc4g1JGaqYTXQo3KAruNRuHff305iw=dEVPsg@mail.gmail.com>
	<alpine.DEB.2.22.394.2109! 301236020.1807498@pseudo>
	<CAJ7c6TNv7rOdQkWwVDDVQ3A8X=KbPvG_3pUZ5dctz8JDEW4FZA@mail.gmail.com>
	<438984.1637951199@sss.pgh.pa.us>
	<alpine.DEB.2.22.394.2111271951200.22329! 1@pseudo>
	<600733.1638042551@sss.pgh.pa.us>
	<alpine.DEB.2.22.394.2111280837520.223291@pseudo>

Fabien COELHO <coelho@cri.ensmp.fr> 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





view thread (59+ messages)  latest in thread

Message-ID: <1119725.1638153641@sss.pgh.pa.us>
Permalink:  ../1119725.1638153641@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1119725.1638153641@sss.pgh.pa.us

 · 

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-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, coelho@cri.ensmp.fr, aleksander@timescale.com, thomas.munro@gmail.com
  Subject: Re: rand48 replacement
  In-Reply-To: <1119725.1638153641@sss.pgh.pa.us>
  References: <alpine.DEB.2.22.394.2105241211230.165418@pseudo> <3b12e2dea4c3c33665c33b40c95349ef@postgrespro.ru> <alpine.DEB.2.22.394.2107060956180.3858351@pseudo> <8904daa4a916b4990b11d7140e0ff81f@postgrespro.ru> <alpine.DEB.2.22.394.2107072036140.4160419@pseudo> <CAJ7c6TOjfmtyBFZUzGLTSvSGydxUTjY67kn-FFrSUBgEpy7zrw@mail.gmail.com> <alpine.DEB.2.22.394.2109250938560.3216312@pseudo> <alpine.DEB.2.22.394.2109251643350.3216312@pseudo> <alpine.DEB.2.22.394.2109251824550.3216312@pseudo> <2520097.1632590602@sss.pgh.pa.us> <alpine.DEB.2.22.394.2109251929180.3216312@pseudo> <alpine.DEB.2.22.394.2109301015090.1807498@pseudo> <CA+hUKGL_R4Aujuc4g1JGaqYTXQo3KAruNRuHff305iw=dEVPsg@mail.gmail.com> <CAJ7c6TNv7rOdQkWwVDDVQ3A8X=KbPvG_3pUZ5dctz8JDEW4FZA@mail.gmail.com> <438984.1637951199@sss.pgh.pa.us> <600733.1638042551@sss.pgh.pa.us> <alpine.DEB.2.22.394.2111280837520.223291@pseudo> <1119725.1638153641@sss.pgh.pa.us>

* 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