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 1mqgr0-0004c2-1l for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Nov 2021 19:25:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mqgqy-0005TG-Qi for pgsql-hackers@arkaria.postgresql.org; Fri, 26 Nov 2021 19:25:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mqgqy-0005T6-HA for pgsql-hackers@lists.postgresql.org; Fri, 26 Nov 2021 19:25:48 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mqgqw-0007No-Gt for pgsql-hackers@lists.postgresql.org; Fri, 26 Nov 2021 19:25:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 1AQJPRXY443133; Fri, 26 Nov 2021 14:25:28 -0500 From: Tom Lane To: Fabien COELHO cc: Aleksander Alekseev , Thomas Munro , PostgreSQL Developers Subject: Re: rand48 replacement In-reply-to: <438984.1637951199@sss.pgh.pa.us> References: <3136e2672d5ab395521bae05a80df469@postgrespro.ru> <3b12e2dea4c3c33665c33b40c95349ef@postgrespro.ru> <8904daa4a916b4990b11d7140e0ff81f@postgrespro.ru> <2520097.1632590602@sss.pgh.pa.us> <438984.1637951199@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Fri, 26 Nov 2021 13:26:39 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <443131.1637954727.1@sss.pgh.pa.us> Date: Fri, 26 Nov 2021 14:25:27 -0500 Message-ID: <443132.1637954727@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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