Re: [PATCH] Introduce array_shuffle() and array_sample()

Fabien COELHO <coelho@cri.ensmp.fr>

From: Fabien COELHO <coelho@cri.ensmp.fr>
To: Martin Kalcher <martin.kalcher@aboutsource.net>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, Andres Freund <andres@anarazel.de>, Dean Rasheed <dean.a.rasheed@gmail.com>, Robert Haas <robertmhaas@gmail.com>, Andrew Dunstan <andrew@dunslane.net>, John Naylor <john.naylor@enterprisedb.com>, Thomas Munro <thomas.munro@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-09-28T13:07:06Z
Lists: pgsql-hackers, pgsql-general
>> With our current PRNG infrastructure it doesn't cost much to have
>> a separate PRNG for every purpose.  I don't object to having
>> array_shuffle() and array_sample() share one PRNG, but I don't
>> think it should go much further than that.
>
> Thanks for your thoughts, Tom. I have a couple of questions. Should we 
> introduce a new seed function for the new PRNG state, used by array_shuffle() 
> and array_sample()? What would be a good name? Or should those functions use 
> pg_global_prng_state? Is it safe to assume, that pg_global_prng_state is 
> seeded?

I'd suggest to use the existing global state. The global state should be 
seeded at the process start, AFAIKR.

-- 
Fabien.



Commits

  1. Add array_sample() and array_shuffle() functions.

  2. Use a separate random seed for SQL random()/setseed() functions.