Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112527 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 67227 invoked from network); 16 Dec 2020 16:44:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Dec 2020 16:44:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2659E180384 for ; Wed, 16 Dec 2020 08:15:20 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 16 Dec 2020 08:15:19 -0800 (PST) Received: by mail-lf1-f52.google.com with SMTP id l11so49771863lfg.0 for ; Wed, 16 Dec 2020 08:15:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oUO06aroVzHtELQohIZhnoYhOk0BBv+YhmRp8IZscQk=; b=DivbAoMefryyehkBfb7e9dTFyPeCXu4uiZSOvZWS4AkLAE5EPw9i9dJQQIfiezg/6a Xt4Vmg4Jq1+hpDXjUTcziNXaWV7ASNRwIRriMfBX754jhuw/s7nc4eQ/JHhPhXw4vU7c qem4lF1qCrutnUFUy9as2O8fexDEvwNWRqHauZt/VT8FLDqhTJfWSAmQeAYZEVJoNKxJ 0hUhU985y3W+TnkKBcTfV3vKUUaG4S/xTWJZz9B+26qw8m+S+nVVtnRBn7W4Ql0CpRjH KF97Cy9A8G/BJIicoTCbKKmvIfx7n/DkEpXfvFfCuAtSbzOteAbJLQ4LVZsIbnNx+L4O BMHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oUO06aroVzHtELQohIZhnoYhOk0BBv+YhmRp8IZscQk=; b=roEepbius+iisY4UmBYcz4E1Y10Wy7fEyRu2cdIyKTY28/SqF48A/pWWCzHBFJjyoc H3iBFVs3W9h1uc5yU7rSLQQTV7Fc3169e6A8xplaSJqqiNqz29Q/BMkbEqkQtTmLv8Ni nwOLnknOks2AowjMAWoYTS+dac0pGr+6FWn4S4UbKOVgUfL1SYdpBmRGxW2bBbURfi8R eqtPJs/jPkCwyG72Z9CfcTt95D5ZM1buAhyQrp1FIYv8p2MhlvkaryZlT1c0VkZZkEk7 f/wP8loTUF7o32PGSSRCcz5UKhCuPwm4CyBDhtpJZbDU1XIcaVU7Ao3C35ObyA6QgFmh GZbQ== X-Gm-Message-State: AOAM530CDZl769Ow+DVk0Z2obMN+HLiHHImjrHEFifLgmA08/elOaFkt Zp96qipiMBQOeM/ptf5q/aha56/40kLx/Fxeny4= X-Google-Smtp-Source: ABdhPJyN3lyePJnnXj8unTCRrWIwC8e3gFOXrY5fYWexspS7rwCRpqxi3Cen5ajiWIqzOqbCPdGHER4ytdITB1n+Chs= X-Received: by 2002:a05:6512:108b:: with SMTP id j11mr14509243lfg.44.1608135318240; Wed, 16 Dec 2020 08:15:18 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 16 Dec 2020 17:15:02 +0100 Message-ID: To: Sara Golemon Cc: zeriyoshi , PHP internals Content-Type: multipart/alternative; boundary="00000000000065020905b6972ef6" Subject: Re: [PHP-DEV] Improving PRNG implementation. From: nikita.ppv@gmail.com (Nikita Popov) --00000000000065020905b6972ef6 Content-Type: text/plain; charset="UTF-8" On Wed, Dec 16, 2020 at 4:56 PM Sara Golemon wrote: > On Wed, Dec 16, 2020 at 8:46 AM zeriyoshi wrote: > > Nice to meet you, internals. > > > > Welcome! I'm about to knock down your suggestion a little, but please take > it as constructive feedback. > > > First , PHP has the historical Mersenne Twister PRNG. However, this > > implementation keeps its state in a global and cannot be handled as an > > object like other languages (e.g. Java). > > > > Can you clarify what object handling provides? Is the intent to have an > expanded API for producing a reliably predictable series of numbers based > on more finely tunable seeds? Iterable PRNG generator? > I expect the main use-case is generation of predictable random numbers based on a seed, in a way that does not rely on global state. mt_srand() + mt_rand() provide the basic functionality, but because they are using global state, any other library that also happens to use mt_rand() somewhere will screw up your seed sequence. You need to implement your own PRNG in userland, which will be slower (esp. as RNGs usually require wrapping math, which is not efficiently supported in PHP). Additionally, if you want to perform something like an array_rand() based on your independent RNG stream, there's no way you can do that efficiently (as you don't have random access into the underlying data array). As such, I do like the idea of providing this functionality, as it falls squarely in the area of "performance sensitive and hard to implement in userland", which is exactly the kind of functionality we can justify having in the standard library. (The abstract functionality, no comment on the particular implementation used here.) Regards, Nikita > > So, I created a PHP Extension and proposed it to PECL. > > > > https://marc.info/?l=pecl-dev&m=160795415604102&w=2 > > https://github.com/zeriyoshi/php-ext-orng > > > > Bundling extensions usually comes when an extension has shown widespread > popularity/use. With all due respect, this repo is less than two weeks old > and has 8 stars. Who needs this and why is it not services by the PRNG and > CSPRNG options already available? > > > With the development of container technology, this problem seems to be > > getting more serious. So I think we should use the random numbers > provided > > by the OS (getrandom on Linux) if available. > > > > We've had that since 7.0: > > https://www.php.net/random_bytes > https://www.php.net/random_int > > -Sara > --00000000000065020905b6972ef6--