Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117029 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 83956 invoked from network); 14 Feb 2022 14:26:37 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Feb 2022 14:26:37 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D0A631804D0 for ; Mon, 14 Feb 2022 07:44:06 -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 ; Mon, 14 Feb 2022 07:44:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1644853443; bh=fKXVqO8ijOxchS8VOIANBqoinHjrhaBVK9P2Whro+ZE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=AGiJL2crW2YSlhnu2HcZQkLTvEZpG7Eqsv32UXJj9ZbUJJufUg2LyjwfjO9zQpj/o 7KGvFtiDkR04baraF6BwLwKNKYBq8qgNv7siR8x28o7fEpBfwouoRSVj1wXp7KyS+j Yoj/NSsI6eJoGxDZAg20NK7ThL6hP5YYoJmmcs4L0rPfF/DLDK2S9bD55klquMo1cg quaW+UhlI2fyr5RrXq4TmnH2mm7k68WuNi6Bj6OVWHzai+m/cjFq+5lg1fu8uiEDR4 w1PJh7gbftTVrwSfV89TBJuqetxUjecgOsWL8ZkF0ykZppgAEVJLLxjEEJaUm+dFBw p6QhCj/r/XFEA== Message-ID: <553ba7ca-3821-c2d9-f88f-b216013a887b@bastelstu.be> Date: Mon, 14 Feb 2022 16:44:02 +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> 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: timwolla@bastelstu.be (=?UTF-8?Q?Tim_D=c3=bcsterhus?=) Hi On 2/14/22 15:53, Go Kudo wrote: >> 1) XorShift128+ has a 128 Bit internal state, but takes an integer seed > within the constructor. Thus only 64 Bits of seed can be provided. > > This is for convenience. Other software that uses XorShift128+, such as > Chromium (V8), also uses a 64-bit value for the initial seed value. > I think that 128-bit value seeding with strings is unintuitive and not very > good for performance. > > https://chromium.googlesource.com/v8/v8/+/refs/heads/main/src/base/utils/random-number-generator.h I don't think performance for seeding the RNG matters. That's an operation you only perform once (or a small number of times). The time for the actual generation of random numbers most certainly dwarfs the time used for seeding. Regarding "unintuitive": I disagree. I find it unintuitive that there are some RNG sequences that I can't access when providing a seed. I wouldn't object a convenience constructor that also accepts an integer, but I believe the default should be a seed that is appropriate to generate the full state space. >> 2) I would adjust the 'Randomizer' to use the 'Secure' generator as a > safe default. If absolute performance or a reproducible sequence is > required then one can use a custom generator, but the default will be the > secure CSPRNG, making it harder to misuse. > > Certainly, this may be appropriate. But, in this case, the Randomizer > generated with the default parameters will not be serializable. Is that > acceptable? I consider that acceptable. If I want to serialize the randomizer then I want a reproducible sequence and in that case I should also be forced to explicitly decide what type of reproducible sequence I want. If I don't explicitly decide, then newly generated randomizers might use an entirely different generator if the default changes., >> 4) The RFC should document the 'NumberGenerator' interface. Specifically > I'm interested in the return type of the 'generate' method. Does it return > bytes or integers? Is it legal to implement the interface in userland code? > > It returns an int. Also, as pointed out in GH, the generated value is > implicitly treated as the size equivalent of PHP_INT_SIZE (zend_long) on > the environment. This means that it is not possible to implement the > userland Mersenne twister (32-bit) in a 64-bit environment. I think the returned value of the generator should be a string containing raw bytes. It's very easy to interpret a bytestring as an appropriate integer (e.g. using unpack()), but if some consumer needs a bytestring then turning the integer back into a bytestring without accidentally introducing biases is much harder, because of platform differences and the lack of unsigned integers in userland. Unfortunately your PR doesn't compile for me, so I can't test: make: *** No rule to make target 'php-src/ext/standard/lcg.c', needed by 'ext/standard/lcg.lo'. Stop. Best regards Tim Düsterhus