Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117045 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 12511 invoked from network); 16 Feb 2022 09:46:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Feb 2022 09:46:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E7D2F1804C9 for ; Wed, 16 Feb 2022 03:04:17 -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,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-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (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 Feb 2022 03:04:17 -0800 (PST) Received: by mail-yb1-f182.google.com with SMTP id 124so4810679ybn.11 for ; Wed, 16 Feb 2022 03:04:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=colopl.co.jp; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=b3HJqlbTTok8ThqmX3rv/3yoWf/cbfPJGYcCbNQERuQ=; b=Qn8xsDc/eGQHGEhwf/HMU9fZ+niJU1s6NJF8E/wE8AKb+PPU8pf62R5fKzbeCj/J2S LXOZQiCyMENQAAQXjWxroPI6SyWFNOmd7DGzUgREku+D/nJ67O5aEmQ8XjMsDOYtoMPX iFp4oLGyE8Lc3pdgcsWz+FeDTPHZMbBBBGctx3T73NngZIU5/mIE5gRCEz7cqX/md7E1 OcM1cpBWrA6Ow4JbJ3PjqG5TyFqHQtrqikXNwMnsaloNVoGtJn6F7moeggbx7GQ5zHN0 tUfJuif9m04zYCPBCUQpA4cMkgyOOglC27CmA40A/AUqAsBZ3UNzftBd7HREJQi75Tc/ FweA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=b3HJqlbTTok8ThqmX3rv/3yoWf/cbfPJGYcCbNQERuQ=; b=zIEfDE1fXaHuaTg8WV0y0SY46xIHYhgVU6n44bkuyNkW6w+goXxbQQEfav+HLTNCnM hWQsZ+3kPZLiZkbEnClu8uKgLZryl9xiO4qw17LREi+YFRf61cNxleRz+qz5tW4bdcR5 akOLe/EfCZcAkZ2Gf0j5lESb4Kd5XeeHy5Hf4sH2jCHidKesuDZqwhSG3/QFlbO7kOL3 DBdIsfVitijjxCRw32vfoliWXOId/OG5wPh7kEcjC6c5PTR6g+LzBp1EKHZR2b+Bm51a SRWKhOm3O5aL/616I0DWRf3jl167ODbPk/VX4bZYg5dnMHmZQ5fwwMc3/hxQG9T4zbNO heUQ== X-Gm-Message-State: AOAM530vzbZwOdnlczqZhjfTtNOYRTFpPgdGhxpEcAtMos3NPZEwMuV3 q45KJv61jVvczwyqYumKOmhj461DBIQBqudbyPOeO0NNQRi4 X-Google-Smtp-Source: ABdhPJwUcDp/nPHA9wAFKuOUwsW0yt7VTXZS8CoFQfLb7Z9saAjwlvzKHLbjPn72JAhKl7vYZ+C8RxCYdZWa+LXFcNY= X-Received: by 2002:a81:7904:0:b0:2cb:7af3:c096 with SMTP id u4-20020a817904000000b002cb7af3c096mr1893081ywc.98.1645009456981; Wed, 16 Feb 2022 03:04:16 -0800 (PST) MIME-Version: 1.0 References: <41a1b458-4941-f34e-f1b4-e25b3298b80a@bastelstu.be> <553ba7ca-3821-c2d9-f88f-b216013a887b@bastelstu.be> <2c667812-88c8-0b7b-3558-561a1348d0b2@bastelstu.be> In-Reply-To: Date: Wed, 16 Feb 2022 20:04:06 +0900 Message-ID: To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="00000000000056025f05d8209cfa" Subject: Re: [PHP-DEV] [RFC] [Under Discussion] Random Extension 4.0 From: g-kudo@colopl.co.jp (Go Kudo) --00000000000056025f05d8209cfa Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2022=E5=B9=B42=E6=9C=8815=E6=97=A5(=E7=81=AB) 22:09 Tim D=C3=BCsterhus : > Hi > > On 2/15/22 12:48, Go Kudo wrote: > > At first, I updated the RFC to the latest status. > > > > https://wiki.php.net/rfc/rng_extension > > Thank you, the examples are useful. > > > I need some time to think about the current issue. I understand its > > usefulness, but I feel uncomfortable with the fact that the > NumberGenerator > > generates a string. > > Would you feel more comfortable if the interface would be called > \Random\Engine or \Random\Generator (i.e. leaving out the "Number" from > the interface name)? > > Engine is the term used by C++: > https://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine > Generator is the term used by Java: > > https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/ra= ndom/RandomGenerator.html > > ---------- > > With the 'FixedForUnitTest' example you mentioned in the RFC: While for > that specific implementation it appears pretty obvious that increasing > numbers are generated, in practice: > > 1. This will result in inconsistent behavior based on the architecture. > I can't test it due to the lack of the necessary architectures, but I > believe the following to be accurate: > > $g =3D new FixedForUnitTest(); > > $r =3D new Randomizer($g); > > // 0100000000000000 in 64 Bit little endian > // 0100000002000000 in 32 Bit little endian > // 0000000000000001 in 64 Bit big endian > var_dump(bin2hex($r->getBytes(8))); > > 2. This analogy completely breaks down for the 'shuffle' functions which > call the generator internally an unspecified number of times: > > $g =3D new FixedForUnitTest(); > > $r =3D new Randomizer($g); > > var_dump($r->shuffleString("abcdefghijklmnopqrstuvwxyz")); // > wosqyrupatvxznmlkjihgfedcb > var_dump($r->shuffleString("abcdefghijklmnopqrstuvwxyz")); // > fwrtjndlsyvpzuhxbqomkigeca > > The resulting strings look somewhat ordered, but there is no clear > pattern, despite the underlying generator being completely predictable! > > > I also wonder about the point of changing RNG to XorShift128Plus. There > are > > a number of derived implementations, which RNG do you think is more > > suitable? > > > > I'm not an expert in RNGs, but based off this page: > https://prng.di.unimi.it/ and the linked papers it appears that > xoshiro256** is the overall best choice if memory usage is not a concern. > > Best regards > Tim D=C3=BCsterhus > Hi Tim. Thanks for the good idea. I changed the NumberGenerator to Engine and changed generate() to return a string as suggested. The main changes since last time are as follows: - The userland implementation can now specify the width of the random number sequence that can be generated - Random\Engine::nextByteSize() has been added - Random\Engine::generate() now returns a string - Random\Randomizer::getInt() now accepts an empty argument (like mt_rand()= ) At the same time, I have updated the RFC. https://wiki.php.net/rfc/rng_extension I have not yet come to a final conclusion on whether XorShift128Plus should be switched to another RNG. For example, what about implementing XorShift128Plus, but adding Xoshiro256** as well? --00000000000056025f05d8209cfa--