Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116023 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78922 invoked from network); 9 Sep 2021 03:53:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Sep 2021 03:53:19 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DB1C71804AA for ; Wed, 8 Sep 2021 21:31:11 -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_H3,RCVD_IN_MSPIKE_WL,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-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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, 8 Sep 2021 21:31:10 -0700 (PDT) Received: by mail-ej1-f41.google.com with SMTP id bt14so891156ejb.3 for ; Wed, 08 Sep 2021 21:31:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=5osmOLjupE0hYKAytugC2ne0UFuegxF/BvxFQPXFY+4=; b=m0DCxbYqgOtqbIJW6YzVQ+x9o95tNMaUnC745GC7qx5A1G8FEH5A6EyMA9R2dw55eR nKXAWeSpXeNpshflD+00JN6UYCOIDUYZD8ZHYdygKUEn1xvfOBvWPxeHtCymhMln3RYz q8tjZDGKCtm49HFEAKwcdPJmwTEmEYGuya9DdzoradEFBxWlwxWPxh/4huK2TNwOK8W/ xWDBt2HFM/+UZoGj2ZLuA+OcjguMOTG01SJvcP1vOtzbcQdGKHC3Dz+0T0QX5eVeOa1e tlgRdojokcRMHZQV2Tb89jiQWfUrRV0KBr6uemuDm5jMEU9pnD+GndrYMumD8kO0CQqT 23dA== 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; bh=5osmOLjupE0hYKAytugC2ne0UFuegxF/BvxFQPXFY+4=; b=aMsc6d7kAzyF+1TrUK9qIu39ENAVOTafMJoJZIHLK0lGSjk8my80yOW7d+hlOA5zp8 wpSepmPet+1P0/XxsEqEpdZWrX/tr/W8I2aKd5++qsjFj79r0GRtUt3esoJ+7q8ILOOz ey5zJ7P7rrBe/C4ZG2zCC1dBvU49+NfhwJOfgK6Sj6GJd0vGCkUYNgfcCsR0x3AVG3Az YcQrTass/Ugz+usXMZtpbefXj+OBzc1Mx8tpKFyZA4KqJwTwRZCi7oEgNN91EoVFPHWs W88pe4TSCS0yAd+zZWDOWWuI6OYbE3d4hbqNQCH1Vkhi0RjwiG47CISJqNrbytdYNPmp 4z2w== X-Gm-Message-State: AOAM530rurjmwmxmaWQT6SthsoXUiWJvViXylCdDlzOSVy2/Kg9Wv92k FcDPULUmQkkkL9vrzh7SVyZ3nuh3T77HmzJeIB8TJB8X/cA= X-Google-Smtp-Source: ABdhPJy6/wJ0ni75msiZgDJqHB9dUsjpXsFaADAIHaW0l67dgbghcKUTQA4Z30zWLNwXWLKqgpLRTAlN3ONgtEQns4c= X-Received: by 2002:a17:906:720e:: with SMTP id m14mr1247212ejk.500.1631161869256; Wed, 08 Sep 2021 21:31:09 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 9 Sep 2021 13:30:58 +0900 Message-ID: To: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary="000000000000c9cd8105cb8877b5" Subject: Re: [PHP-DEV] [RFC] Random Extension 3.0 From: zeriyoshi@gmail.com (Go Kudo) --000000000000c9cd8105cb8877b5 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Nikita, sorry for the late reply. This is a difficult problem. For now, MT19937 is left for compatibility. In other words, if you don't need compatibility, there is no benefit to using it. What about implementing both a new MT and a compatible MT? A compatible MT would have the following signature ```php use Random\NumberGenerator\Numbergenerator; /* for legacy compatibility */ class MT19937 implements NumberGenerator { public function __construct(int $mode =3D MT_RAND_MT19937, int $seed) {= } } /* a new implementation */ class MersenneTwister implements NumberGenerator { public function __construct(int $seed) {} } ``` I had originally removed the MT_RAND_PHP implementation on the grounds that legacy implementations should not be retained, but if the regular Mersenne twister is to be retained for compatibility, I think it should be as well. Also, maybe we should opt for a more SIMD friendly RNG. Regards, Go Kudo 2021=E5=B9=B49=E6=9C=887=E6=97=A5(=E7=81=AB) 17:28 Nikita Popov : > On Thu, Sep 2, 2021 at 5:10 PM Go Kudo wrote: > >> Hi Internals. >> >> Expanded from the previous RFC and changed it to an RFC that organizes t= he >> whole PHP random number generator. Also, the target version has been >> changed to 8.2. >> >> https://wiki.php.net/rfc/rng_extension >> https://github.com/php/php-src/pull/7453 >> >> Hopefully you will get some good responses. >> > > This RFC currently tries to keep some semblance of compatibility with the > existing mt_rand() algorithm by retaining the same implementation for > mapping the raw random number stream into a range. However, the algorithm > we use for that is not exactly state of the art and requires two full-wid= th > divisions at minimum. There are more efficient scaling algorithms based o= n > fixed-point multiplication, which are "nearly divisionless" ( > https://arxiv.org/pdf/1805.10941.pdf). The variant at > https://github.com/apple/swift/pull/39143 is entirely divisionless. > > Doing this would improve performance (though I'm not sure by how much -- > maybe once we add up our call overhead, it isn't important anymore?) but = it > would provide a different sequence than mt_rand(). Something we might wan= t > to consider. > > Regards, > Nikita > --000000000000c9cd8105cb8877b5--