Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114783 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33756 invoked from network); 8 Jun 2021 12:56:06 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Jun 2021 12:56:06 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CE5BB180537 for ; Tue, 8 Jun 2021 06:10:51 -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-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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, 8 Jun 2021 06:10:51 -0700 (PDT) Received: by mail-ed1-f48.google.com with SMTP id b11so24458029edy.4 for ; Tue, 08 Jun 2021 06:10:51 -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=y8lCdNOXr1vD8DRRAhi85nbKiJDD5T+poyPqGKvxtTc=; b=NoUg9PNZHjoJQgnbBxT1HEIblI0rPzDQjMBaVUrzKu6EhROUGz5elNUurkd+Hr6c+Y PGsGmFT9uHyK1og0+hht5ZhmZyBj0tGDruvrM6NkvyjBLBlDZLsmOIT3G5LJNwxX7pPy hXoXi8rBTMz6pDpBz/l9pi1eIpVhioq2REXKc1g/NJf+4OZGW53nzinYK47isjuuRVUk AD0BZXop2zw18+a+f4jkQC0Px1TX4wZP4aNsnXSkKR28jiwfYjU37AwKVNfVWwtJpyeC x/Be+w3YvsPrXCa1Z+IleBSkf2Qw0qND9DCNnhs5vXMOYiEEmlZKx582VXy5eS86+Eik y7HQ== 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=y8lCdNOXr1vD8DRRAhi85nbKiJDD5T+poyPqGKvxtTc=; b=rUc5qoRnLYu3EhLdWIFvvX0jrzsFbshQiCQYxX35E1zS425EBq9Q6RvWCZOpaVBPxW Imjdln6dbK4CAuoBSP1mMJKBAhWKV6SbGyxN73etcHL/g/zGFiqa7dlc/qZvKgCgYk8v UqG33gOhKlpPyh7NVYsOfL32au09SGZfAIn8gm7vtfQ9GAO0+8WzSRl356nuAPLi5Tej 9jEK8p3hFJb5Xgh4lk4ZnlGoF/Zv+jOUkcFMLZ3z+mfcx2Fyfipvugg9+nE/Gnb24Dz3 zp95uqXMTm4iGPl5/vhACGbUB5BoWBZGhg2GwvaM2uQMANByN1x3SLkGIA+cVFLbf0fb ObRQ== X-Gm-Message-State: AOAM533LGn8nh8oBNoiJfgfd8iZATcgXpVRVnitS5sUO3DJnkCeAbjvJ Q+b2u7CgSPMrN/N8wCGnePqlG+ca1GeNUACIkaMVaOuDnpsuAQ== X-Google-Smtp-Source: ABdhPJyh5W5g82FlfRnKxM/mpTqKaWPpZFsWTlJHn1NePwh1pj/HiKxwuy40hZWn8dk3kckwtZ9yZxcVGbP8Rreh6Fw= X-Received: by 2002:a05:6402:348f:: with SMTP id v15mr13467364edc.135.1623157849231; Tue, 08 Jun 2021 06:10:49 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 8 Jun 2021 22:10:38 +0900 Message-ID: To: Jordi Boggiano , PHP internals Content-Type: multipart/alternative; boundary="00000000000004942905c440e3d9" Subject: Re: [PHP-DEV] [RFC] Under Discussion: Add Random class and RandomNumberGenerator interface From: zeriyoshi@gmail.com (Go Kudo) --00000000000004942905c440e3d9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sorry, I missed the first question. > "Random class can be serialized or cloned if the algorithm supports it." It isn't clear to me how that support is defined in a userland implementation? Simply by implementing __serialize/__unserialize? Userland implementations can be serialize / unserialize using the standard PHP serialization mechanism. For example, the following: ```php class UserRNG implements RandomNumberGenerator { protected int $current =3D 0; public function generate(): int { return ++$this->current; } } $random =3D new Random(new UserRNG()); $random->nextInt(); $random_serialized =3D serialize($random); var_dump($random_serialized); // O:6:"Random":2:{i:0;a:1:{s:11:"Randomrng";O:7:"UserRNG":1:{s:10:"*current";= i:1;}}i:1;N;} $random_unserialized =3D unserialize($random_serialized); var_dump($random->nextInt() =3D=3D=3D $random_unserialized->nextInt()); // = true ``` Regards, Go Kudo 2021=E5=B9=B46=E6=9C=882=E6=97=A5(=E6=B0=B4) 17:51 Jordi Boggiano : > On 01/06/2021 16:28, Go Kudo wrote: > > Hello internals. > > Thanks for continuing to participate in the discussion. > > > > I've sorted out the proposal, and finished writing and implementing the > RFC. > > (Funny, I know.) I think it's time to start a discussion. > > > > https://wiki.php.net/rfc/rng_extension > > https://github.com/php/php-src/pull/7079 > > > > The main changes since last time are as follows: > > > > - The ugly RANDOM_USER has been removed. > > - RandomNumberGenerator interface has been added for user-defined RNGs. > > - Random class is now final. > > - Random class now accepts a RandomNumberGenerator interface other than > > string as the first argument to the constructor. > > - INI directive has been removed. In 32-bit environments, the result is > > always truncated. > > Overall this looks much better! From a PHP userland perspective I can't > see any huge problem at first glance. > > Just a few notes: > > - "Random class can be serialized or cloned if the algorithm supports > it." It isn't clear to me how that support is defined in a userland > implementation? Simply by implementing __serialize/__unserialize? > - The __unserialize docblock has two typos (Useri*i*alize and *in* > instead of if) > - If an object is passed to `new Random($obj)`, probably it should throw > an InvalidArgumentException if a seed is also passed in, as I assume in > that case it would be otherwise be ignored. > > Best, > Jordi > > -- > Jordi Boggiano > @seldaek - https://seld.be > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --00000000000004942905c440e3d9--