Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117040 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48818 invoked from network); 15 Feb 2022 11:51:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Feb 2022 11:51:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1CF72180511 for ; Tue, 15 Feb 2022 05:09:14 -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=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS24940 176.9.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 15 Feb 2022 05:09:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1644930551; bh=e2c0YA09cuKIL/xgTHhz8pU61E35NX7+geFh4Zqvwy4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=cjA5MP9HkW5xq78JWNo4Lkx+fKjDleVzFPO2xK9/sOnU9dPu9+Y202B8lhu/QYg3M 1i8bLFXnbulT+rs+r9HycSJ+SS/BAp061EpWX0gKe9wa11YxPxFgKqZlBi1SCT4KVa EOSOJXgVw1GBOM5y9OFXgGKS+NluzHEdx49Z9CLfl19qGes/1yRx97KJsxya1yyyaJ I+zwnOnsZ6DroWtcPhbcqYtP4zVS+5sEZ1mJQuym6mXrKdTWTXumt032SxTBahn320 BM61+ShJe+M5VCQUzypRcpnPBghKJIz/xnNxBllMMhRKTu7U4sARYY0IFWqwhbt7Gq 4ixZAI37dGkmw== Message-ID: Date: Tue, 15 Feb 2022 14:09:10 +0100 MIME-Version: 1.0 Content-Language: en-US To: Go Kudo Cc: internals@lists.php.net 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: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] [Under Discussion] Random Extension 4.0 From: tim@bastelstu.be (=?UTF-8?Q?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/random/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 = new FixedForUnitTest(); $r = 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 = new FixedForUnitTest(); $r = 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üsterhus