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: Fri, 26 Nov 2021 14:25:27 -0500
Message-ID: <443132.1637954727@sss.pgh.pa.us> (raw)
In-Reply-To: <438984.1637951199@sss.pgh.pa.us>
References: <alpine.DEB.2.22.394.2105241211230.165418@pseudo>
	<alpine.DEB.2.22.394.2107041718570.2359988@pseudo>
	<CAEZATCWnrVACs2FM219dSkh1ivic8KiGkPEVPtu-MO3nCOYm7A@mail.gmail.com>
	<alpine.DEB.2.22.394.2107042204240.2359988@pseudo>
	<3136e2672d5ab395521bae05a80df469@postgrespro.ru>
	<alpine.DEB.2.22.394.2107060805140.3858351@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>

I wrote:
> ... What we do need is a decision
> about what to do on Windows.  We could write it like
> +#ifndef WIN32
> +	srandom(pg_prng_i32(&pg_global_prng_state));
> +#endif
> but I have a different modest suggestion: add
> #define srandom(seed) srand(seed)
> in win32_port.h.  As far as I can see from Microsoft's docs [1],
> srand() is exactly like srandom(), they just had some compulsion
> to not be POSIX-compatible.

Oh, wait, I take that back --- rand()/srand() are also in POSIX,
and in the C99 standard (which presumably is where Microsoft got
them from).  They're deprecated by POSIX on the grounds that the
spec only allows them to have 32 bits of state, so they can't be
terribly random.  Given that, I think we should just avert our eyes;
anybody depending on those functions is destined to lose anyway.
Probably the "#ifndef WIN32" fragment suggested above is enough.
I suppose we could *also* call srand() but that feels a bit silly.

			regards, tom lane





view thread (59+ messages)  latest in thread

Message-ID: <443132.1637954727@sss.pgh.pa.us>
Permalink:  ../443132.1637954727@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/443132.1637954727@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: <443132.1637954727@sss.pgh.pa.us>
  References: <alpine.DEB.2.22.394.2105241211230.165418@pseudo> <alpine.DEB.2.22.394.2107042204240.2359988@pseudo> <3136e2672d5ab395521bae05a80df469@postgrespro.ru> <alpine.DEB.2.22.394.2107060805140.3858351@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> <443132.1637954727@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