Re: rand48 replacement

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: Aleksander Alekseev <aleksander(at)timescale(dot)com>, Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: rand48 replacement
Date: 2021-11-29 02:40:41
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Fabien COELHO <coelho(at)cri(dot)ensmp(dot)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

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2021-11-29 02:44:19 Re: enhance pg_log_backend_memory_contexts() to log memory contexts of auxiliary processes
Previous Message Peter Smith 2021-11-29 02:08:21 Re: row filtering for logical replication