Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114678 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63278 invoked from network); 31 May 2021 13:51:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 May 2021 13:51:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 18F9B180532 for ; Mon, 31 May 2021 07:04:30 -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-Virus: No X-Envelope-From: Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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, 31 May 2021 07:04:29 -0700 (PDT) Received: by mail-ed1-f50.google.com with SMTP id s6so13584753edu.10 for ; Mon, 31 May 2021 07:04:29 -0700 (PDT) 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=rNkpBmg3EmTXcPzJQNCpXWT5kdaQjm8d9KIgmGobqFE=; b=E6zyWxp150tHp+blRhXm9YkleFUh+iVf5tIr5d3Yust9mKk9fi1ysgDUheCj/MRyMD w3U92KvLgtbWOCKAGwzNGg11ST0KnU/zAibWiuoxHCTnu52+zd6wmwwsKdiIYnUga+pr TVle0ewZj38TGxsG47hFrE2FqPlU8pXs0wvnCWle2ZhXjTuccyar5RxNJ5/5mRAMWYsX h6jQMP/FEH0Z2StntXEc0gysc7FWGEQSOonAbKUF9xrtFexoWEDTissHCi68ZKOxAI06 MmlbTYrB4zjj7MYfyNq2MptpgeOBkfBUdLv551RRJ+OFGnqEjIc3ZDXsa4BIsEaJo58d bndw== 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=rNkpBmg3EmTXcPzJQNCpXWT5kdaQjm8d9KIgmGobqFE=; b=IphSq84KJiKaUwytNlLVd/4dE7hF/EfryLojfD6sju5pxyUUzS43ZbmNHo/AyOUcPv 1PX1O5cDnECclB7djc8CnD37dnBfk1qv9qQYSRobjVLvButzwiAIM7DxsI6QqgilpeIx qjgcaMOI7umVDCefTa3Xy5o5T3e+M5BDU0TdtNlIzjobPEY0WfhpP8f7GO/g7n1DRxeH x+aOGYwISkdX6fMI6KN1+AJidwh/2ORWNB12ynP+X3Ca5kx1AEpHeWhI7ZKemklLjfLm dtGUHBOkJ76Yo77h9krQpoGWBJdy1dtmnQoxDNEVtATTMuccYfH3T79h8p1C3bR36+3F QA9g== X-Gm-Message-State: AOAM531eKW4FHPP7IjLFI13sC5sEqdyXdhmfN5ztZRhhN/1cT6as4+YS 3uqxYEfDOKlckBcUqjSvS8pjmCLn/oaJwikceL2SPT+xbVk= X-Google-Smtp-Source: ABdhPJxZuEYgOF9VZVD3Dn5WYqQb7tEWqT7+7asK0XGvC9NvWUzijcAWWKpaxEep2mXkT1Hxd0tAw7s9646UDj8yrAk= X-Received: by 2002:aa7:dd81:: with SMTP id g1mr2604670edv.274.1622469865888; Mon, 31 May 2021 07:04:25 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 31 May 2021 23:04:14 +0900 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000003df2005c3a0b401" Subject: Re: [RFC] [Draft] Add Randomizer class (before: Add RNG extension) From: zeriyoshi@gmail.com (Go Kudo) --00000000000003df2005c3a0b401 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Internals. I apologize for the discussion outside the ML. Here's a brief history. https://github.com/php/php-src/pull/7079 - To test the implementation, I sent a Pull-Request to php-src on GitHub. - An excellent point was made, and we ended up having a discussion about it on GitHub. - I was going to change the current implementation RFC to Under Discussion, but decided against it. Also, sorry for the delay in answering your questions. I am not very good at English and it is taking me a long time. The current implementation and RFC: - https://github.com/php/php-src/pull/7079 - https://wiki.php.net/rfc/rng_extension However, the implementation of this user-defined class is very ugly and we intend to improve it as follows. Before: ```php class Random { public function __construct(string $algo =3D RANDOM_XORSHIFT128PLUS, ?i= nt $seed =3D null) {} //.... } class UserDefinedRandom extends Random { protected function next(): int { return 1; } } ``` After: ```php interface RandomNumberGenerator { public function generate(): int; } final class Random { public function __construct(string|RandomNumberGenerator $algo =3D RANDOM_XORSHIFT128PLUS, ?int $seed =3D null) {} } ``` 2021=E5=B9=B45=E6=9C=8826=E6=97=A5(=E6=B0=B4) 0:35 Go Kudo : > Hi, Thanks for the response. > > The RFC has been revised based on the points you pointed out. > > https://wiki.php.net/rfc/rng_extension > > The main changes are as follows: > > - Class name has been changed from `Randomizer` to `Random` . > - Added a static method `getNonBiasedMax()` to get the safe range. > - `int()` and `bytes()` have been renamed to `getInt()` and `getBytes()` > for avoid future reserved words. > - `getInt()` arguments no longer accept null. > - `shuffle(array|string $target): array|string` has been separated into > `arrayShuffle(array $array)` and `stringShuffle(string $string): string` > for more comfortable static-analysis. > - fix: php_random_algo struct (included uint64_t -> int64_t) > > Answer a few questions: > > > When $seed is null, what is used for the seed value? > > Depends on the algo's implementation, but basically it is using internal > `php_random_int()`. > It is similar to `mt_srand()` on PHP 8.1. > > > https://github.com/php/php-src/commit/53ee3f7f897f7ee33a4c452100146480433= 86e13 > > > Why cancelled RNG Extension? > > As a result of discussions during the draft, the functions became a singl= e > class and no longer need to be separated. The functionality for random > numbers is now included in ext/standard and will conform to this. (e.g. > rand.c random.c) > > > Deprecation > > Dropped in the last RFC update. > These were premature and should not have been included with the RFCs that > add new features. > > If the direction seems generally okay, I'd like to start implementing it > to show more details. > > Regards, > Go Kudo > > 2021=E5=B9=B45=E6=9C=8823=E6=97=A5(=E6=97=A5) 5:56 Go Kudo : > >> Hi, Internals and all participated in the previous discussion. >> >> RFCs have been cleaned up and the proposal has been substantially change= d. >> >> https://wiki.php.net/rfc/rng_extension >> >> First of all, I apologize for not checking out the implementation of >> password_hash(), which is a precedent to learn from. >> >> I think I've answered all the questions I've been getting on Open Issues= . >> If I have left anything out, please let me know. >> >> Regards, >> Go Kudo >> > --00000000000003df2005c3a0b401--