Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116213 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 5852 invoked from network); 4 Oct 2021 09:40:25 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Oct 2021 09:40:25 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0DDC11804C5 for ; Mon, 4 Oct 2021 03:24:37 -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=-0.2 required=5.0 tests=BAYES_40,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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 ; Mon, 4 Oct 2021 03:24:36 -0700 (PDT) Received: by mail-ed1-f47.google.com with SMTP id x7so61446734edd.6 for ; Mon, 04 Oct 2021 03:24:36 -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 :cc; bh=xbX/xGBfafAqpQS0UmX4GKFoU1NXv2xcKk11rPEBvC8=; b=Cg8FlzlTbLRUf4T7wR5nOmZKq9O34c5BdEjJKUB8YUCYEFkq56G2waHrBrX4yzWbb8 BHV8j0FjaBMMhP2Iuqum1587Yha9Dee63+y13p/rY+8Gtdi6NdoVu+piMnCNpZ39oY1y YBXxr8gB4iqnEk2iP4cQKW2yVKdHj+Ms+mtmNfyDloXhsanpEh6A4mTDH+906XzFBZv5 zmKRPzLgleLqLLt5LUlvzU1Eu8Kz9KFOsO/8HEpqwKz1pwxBbYyg6xfcrNiGtVoZkzks TFYcDrVZ3JP+OU1rMJmRhWp+WUauhM2qBqcSp5sKO3b83Ufy5HpuD3r0P1GLyCD+siFG xvtw== 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=xbX/xGBfafAqpQS0UmX4GKFoU1NXv2xcKk11rPEBvC8=; b=vcJiUS4kgxpc2a6dcUJsHiMFkCrGoWzPhM/kXVZpphkXFSaunSOwaExtR2kDgMzo8w RXArGNdTJiKZzxMMgVBA/0P0qhZiwcehG2eeTEnP4VBIibETNQjRvWn+uf7eQHHEkfaC u23rJ73C3N1o6i8AvYgrnAM2n8uW6CaU2BxaO2SIZQgiPw92r3ytkCPxAO/FMGvrS2vJ 9w3Ore52Vx7iVZQW3JV4QlXwYhkuoXsMWfq8fENmE/0cF/uGIfxGmk9tbIfokjfeOU8z krYYdk/jba+ScMSzzVBEuQRlGHFON97qZ0rvlJHTcPjErvBR6J6ypgfSrd8FlEAmKSwp sFJg== X-Gm-Message-State: AOAM531gnfyjKoQmlweAzbwZU5Z+/EatOC/yDJRvrIq1AyPumcsBZehd N0kT7vkgIoPenR3cVeZ7/EaYU5NaPN5dlbbk1Zv8oxZw X-Google-Smtp-Source: ABdhPJzeprb3SmaH1Y2KJeQyx6FGiesNEfnGY+1qw1Z2XQxRVwQRfDuvsHcdQVtvAgj8QieaiIhuyabdLdB7SKVEJxQ= X-Received: by 2002:a17:906:2b53:: with SMTP id b19mr11921072ejg.339.1633343075537; Mon, 04 Oct 2021 03:24:35 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 4 Oct 2021 12:24:19 +0200 Message-ID: To: Go Kudo Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000d0585a05cd845113" Subject: Re: [PHP-DEV] [RFC] Random Extension 3.0 From: nikita.ppv@gmail.com (Nikita Popov) --000000000000d0585a05cd845113 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Sep 9, 2021 at 6:31 AM Go Kudo wrote: > 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 M= T > 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 b= e > as well. > > Also, maybe we should opt for a more SIMD friendly RNG. > To clarify, what I had in mind here is not the MT generator itself, but the scaling done in Random::getInt(). This scaling is independent of the used source. So while the raw numbers generated by Random\NumberGenerator\MT19937 would be the same as before, the result produced by Random::getInt() with this source wouldn't be. Regards, Nikita > 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 >>> the >>> 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 th= e >> existing mt_rand() algorithm by retaining the same implementation for >> mapping the raw random number stream into a range. However, the algorith= m >> we use for that is not exactly state of the art and requires two full-wi= dth >> divisions at minimum. There are more efficient scaling algorithms based = on >> 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 wa= nt >> to consider. >> >> Regards, >> Nikita >> > --000000000000d0585a05cd845113--