Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115959 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 64411 invoked from network); 6 Sep 2021 07:29:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Sep 2021 07:29:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2D7671804AD for ; Mon, 6 Sep 2021 01:06:38 -0700 (PDT) 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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 ; Mon, 6 Sep 2021 01:06:37 -0700 (PDT) Received: by mail-ej1-f43.google.com with SMTP id x11so11891941ejv.0 for ; Mon, 06 Sep 2021 01:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=24/fG5ogCB0LidGsdK1JootbMvv+cO8xOO+jNvhZq54=; b=WufKLfBWqEH6ySz3Yh2JmEhpHkdiYYuido7CI/g/3n9PV+2OzC+CiPEos1JK89wyhq GCbmFrYI1RcvDYExam1FZrIQ6n2oQoXDPfBHQcfZTAOyhr5TuKu93tmZDT7UW4qwFF34 ERv3rrAIAty5YPrzUANGruLMGfvM38VqTOQEOm8odshb5Y42rrfzQ/itU5YllLbMqrvk sP3bqWimOuvjSAMuTvs/M/sgvMxVat9SF3k7GW9ckaiWWOwIs7LXOYs4rbaRDzgsa9dW Wucwf8anrSCrbbrDx+dm+B4rxFqy12sLJ37jED6PVmtAyxVE7w4PeSGfkpVcPobVzlGR FJag== 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=24/fG5ogCB0LidGsdK1JootbMvv+cO8xOO+jNvhZq54=; b=dtzIQCWLwzXgxbXrpf85OvaoobZIvJUKc8mxiMS0tIptefxG6QHs9Fbtc0bUMTYhuf xxOLKhzXNaTjGHJQHmiQfdIEVqesPdHfnAym9wIgFOIhcNqDP/ka/tSPPtU3wE/HTzkU BQh8B1Gl19DFt/QQbYkhCErp4j+hmajWvQUwQ49IYXM/Q4EydTqTSdytXtc02Y5rs8m8 TeOyA4Xzl0Lyv9GLckFG+ImtMDss9M9+R0OpDceyEFlqCQVW97uEpGjxw6UKnHy9B4Ni cc76zhnAug9FQD2So2A7z7xmcPIYQgsOIV25vTaoTViFASLjDoZu0jK+yyXjCpLDc5jw ZNJA== X-Gm-Message-State: AOAM532D4EjUXBKWODo14hwmS9cklMyAoJqOorq7yqqeC+wM2KMvIGAw NEvoCg0TTaPFROD68bSNC9pdY3cti0muUqzXQVT+UzXp X-Google-Smtp-Source: ABdhPJxvYERyFu9PwvE39GNomnfetfoxhehvvuhaOVwr5uhpK2j0He9q2tog7E6Tgj9FYQhxXF58ntnBCqtrC1dT+bw= X-Received: by 2002:a17:906:6717:: with SMTP id a23mr12035848ejp.358.1630915594083; Mon, 06 Sep 2021 01:06:34 -0700 (PDT) MIME-Version: 1.0 References: <61339ad1.1c69fb81.b518e.8644SMTPIN_ADDED_MISSING@mx.google.com> <61350112.1c69fb81.82294.dff2SMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: <61350112.1c69fb81.82294.dff2SMTPIN_ADDED_MISSING@mx.google.com> Date: Mon, 6 Sep 2021 10:06:17 +0200 Message-ID: To: Ben Ramsey Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000a4e1db05cb4f2096" Subject: Re: [PHP-DEV] Re: [RFC] Random Extension 3.0 From: nikita.ppv@gmail.com (Nikita Popov) --000000000000a4e1db05cb4f2096 Content-Type: text/plain; charset="UTF-8" On Sun, Sep 5, 2021 at 7:40 PM Ben Ramsey wrote: > Go Kudo wrote on 9/4/21 23:00: > > Indeed, it may be true that these suggestions should not be made all at > > once. If necessary, I would like to propose to organize the RNG > > implementation first. > > > > Do we still need an RFC in this case? I'm not sure I'm not fully > understand > > the criteria for an RFC. Does this internal API change count as a BC > Break > > that requires an RFC? > > Yes, since re-organizing the RNG implementation is a major language > change that affects extensions and other downstream projects, this > requires an RFC. > > >> Personally, I don't see the benefit of including this OOP API in the > core. > > > > On the other hand, can you tell me why you thought it was unnecessary? > > Was my example unrealistic? > > You also said, in reply to Dan Ackroyd: > > > Either way, I'll try to separate these suggestions if necessary, but if > we > > were to try to provide an OOP API without BC Break, what do you think > would > > be the ideal form? > > The OOP API appears to be a wrapper around the RNG functions. The only > thing it gains by being in the core is widespread use, but it loses a > lot of flexibility and maintainability, since the API will be tied to > PHP release cycles. > > By doing this as an OOP wrapper in userland code, you're not restricting > yourself to release only when PHP releases, and you can work with the > community (e.g., the PHP-FIG) to develop interfaces that other projects > might use so they can make use of their own RNGs, etc. > The OO API is not just a wrapper around the RNG functions -- it provides new functionality that cannot be efficiently implemented in userland code. This is for two reasons: 1. It provides independent randomness streams, which means it's not possible to reuse existing functionality like mt_rand() for this purpose, which only provides a single global random number stream. You would have to reimplement the random number generator in userland. While this is possible, it will generally not be efficient, because PHP does not have native support for unsigned modular arithmetic, which is what random number generators generally need. 2. It allows using functions like shuffle() and array_rand() with an independent randomness stream. These functions cannot be efficiently implemented in userland, because userland does not have random access to arrays. Internals can generate a random number and use it to pick the key at that position, which is O(1). Userland would have to call array_keys() first to allow random access on keys, which is O(n). Which is why I think this is a good addition to php-src. There's three good reasons to include functionality in php-src (performance, ubiquity and FFI) and this falls squarely into the first category. And now that we have fibers and need to worry more about multiple independent execution streams, we also need to worry about multiple independent randomness streams. Regards, Nikita --000000000000a4e1db05cb4f2096--