Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112768 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 36901 invoked from network); 5 Jan 2021 18:03:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jan 2021 18:03:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C440C180546 for ; Tue, 5 Jan 2021 09:40:08 -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-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 ; Tue, 5 Jan 2021 09:40:08 -0800 (PST) Received: by mail-lf1-f44.google.com with SMTP id o13so370274lfr.3 for ; Tue, 05 Jan 2021 09:40:08 -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; bh=uwa+on+7SRnl0CewbcvZu7ogVpJ1busCUlSZ+nf1AiI=; b=mJM9xxJbHY1nlyTySKmAMpF5NjHNoSo52oJ2yKp+mx2i1kU1JkUzrJpF4stkDiSi+t XLnugKWcU+pCDVNDf6i6a53xVgWfHWTMQ0bsJmYPivB2+ltq3ZZT01Z1TOu/cZKEw+6F 9cfIvrzzLOuiEIcpIvvzVXEKbWrQOiwdq3SLt4XqS0SgkEpHG4TMbGgUhbJWdP6ZXcKF b3viTmAMgCkXJ5WtWHpwnXwpzfvN7ZDp3U6sPY7V2w7p4YI8MMbcjFMGFv1PF1e80mDK 0n8d2sMvTdVM7Hyz4P9imPKNr+PAWdui1NPr8JwQoFEItNVl5SF9kjpRjhMmanXEUW30 tdAQ== 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; bh=uwa+on+7SRnl0CewbcvZu7ogVpJ1busCUlSZ+nf1AiI=; b=FM620ZGwR4fFv9Y/kPzKhS7nNNbRtdpGjvwmE3XZomtk9zdshF4EsEFTVCwkD/8TIL kD1pl8sLk86HVMWD4hNNpvq1aHFnoYuRVDnpzfVGmxm2Zp5TUe2JYoh7Ezi5YXF+ylr9 v4pUFdnKpitO+kNsTD0fQPpDBEy1+6oMgaY7xk8EKvNBE84SxE4xaLVL7k11vGoom21y Jl9syrss6EboBPh4Bc6gzL7yct4bQ6SI54C7/ya/IG7gbnxR16nHza0hNG5eRQr2Lcmu JJnLH+qFMI470jJNm0ayH5GFbSPSrGFPghfPDNtTNt+B4TFvX1DM1DttxTL8ZHUwmaja 0S4w== X-Gm-Message-State: AOAM530jx6OjSILJKhaSM67YDtYLGbfvU72sVKhSdLlFtEqhULyPcsYA aWrtrOe0Shs3jPbriRxUVDm7EYFwC2QGYyGibgw= X-Google-Smtp-Source: ABdhPJw+KxM0mE6U42Uk/KG7XzdRvJR5ztynh8BQ9hsF8ynD7HbsODJW5a00LrUAYrXplvycTatiBTTBUuICwM9Jrk4= X-Received: by 2002:a19:2c4:: with SMTP id 187mr149077lfc.391.1609868405683; Tue, 05 Jan 2021 09:40:05 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 6 Jan 2021 02:39:54 +0900 Message-ID: To: Nikita Popov , internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000074bb0b05b82ab27c" Subject: Re: [PHP-DEV] Re: Improving PRNG implementation. From: zeriyoshi@gmail.com (Go Kudo) --00000000000074bb0b05b82ab27c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks Nikita. Thanks for the input. This looks like a very smart solution. I've edited the RFC and added a new proposal as TypeC. https://wiki.php.net/rfc/object_scope_prng However, I have a couple of concerns. The first is that users will have to be careful with RNG instances (for better or worse, TypeA will not allow users to use unintended instances), and the second is that it will complicate the implementation of PHP functions. Also, given the current environment in which PHP runs, I think that random number generation in the 64bit range should be supported. How about including the `next64()` method in the interface? Regards, Go Kudo 2021=E5=B9=B41=E6=9C=885=E6=97=A5(=E7=81=AB) 23:53 Nikita Popov : > On Thu, Dec 24, 2020 at 5:12 PM zeriyoshi wrote: > >> I updated the RFC draft and changed it to a proposal to bifurcate the >> interface. >> >> https://wiki.php.net/rfc/object_scope_prng >> >> At the same time, I was looking into the RNG problem in Swoole and found >> out that the problem was actually occurring. >> >> https://www.easyswoole.com/En/Other/random.html >> >> The above problem with Swoole is only for child processes and can be fix= ed >> by the user, but as mentioned above, I think it will become more serious >> as >> PHP becomes more complex in the future. >> I hadn't thought of this before, but we might want to consider deprecati= ng >> existing state-dependent RNG functions. >> >> I am seeking feedback on this proposal in order to take the RFC to the >> next >> step. >> Thank you in advance. >> >> Regards, >> Go Kudo >> > > I think the general direction of your second proposal (B) is the right > one, but I'm concerned about some of the details. > > First and foremost, I don't think that RNG should extend Iterator. Just > having a single "next()" method or similar is sufficient. The Iterator > interface provides many additional things that don't really make sense in > this context and only complicate the implementation. We should clearly > specify the value range of next() though. I assume that for portability > reasons (ensure same sequence on 32-bit and 64-bit) this would have to be= a > sign-extended 32-bit value. > > The type B proposal distinguishes between a RNG and a PRNG interface. Is > this really useful? I don't think the value of the "getSeed()" method is > high enough to justify the split interface. > > The RNGUtil class has methods like: > > public static function shuffleArray(int $randomNumber, array $arr): > array; > > This doesn't make sense to me, as a single random number is not enough to > shuffle a whole array :) Instead this should be accepting the RNG and > perform an internal call to next() (of course, with a fast by-pass > mechanism if the RNG is implemented internally): > > public static function shuffleArray(RNG $rng, array $arr): array; > > I'm also wondering why this is a static class rather than a set of > free-standing functions. Why RNGUtil::shuffleArray() rather than > rng_shuffle_array()? > > Regards, > Nikita > > 2020=E5=B9=B412=E6=9C=8816=E6=97=A5(=E6=B0=B4) 23:46 zeriyoshi : >> >> > Nice to meet you, internals. >> > >> > PHP 8.0 has been released. With the inclusion of JIT, PHP is about to = be >> > extended beyond the web. >> > >> > So I'd like to make a few suggestions. >> > >> > 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). >> > >> > So, I created a PHP Extension and proposed it to PECL. >> > >> > https://marc.info/?l=3Dpecl-dev&m=3D160795415604102&w=3D2 >> > https://github.com/zeriyoshi/php-ext-orng >> > >> > But, Then I looked at the mailing list archives and noticed that a >> similar >> > proposal had been made before. >> > >> > https://externals.io/message/98021#98130 >> > >> > I feel that this suggestion is needed now to expand PHP beyond the web= . >> > >> > Second suggestion is to stop using the Combined LCG as the default see= d >> > value for each function. >> > >> > PHP's Combined LCG only uses PID (or ZTS Thread ID) and time as entrop= y. >> > https://github.com/php/php-src/blob/master/ext/standard/lcg.c#L72 >> > >> > 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. >> > >> > I would like to hear your opinions. >> > >> > Regards >> > Go Kudo >> > >> > --00000000000074bb0b05b82ab27c--