Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116238 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56236 invoked from network); 7 Oct 2021 11:48:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Oct 2021 11:48:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A392B180511 for ; Thu, 7 Oct 2021 05:33:26 -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_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-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (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 ; Thu, 7 Oct 2021 05:33:26 -0700 (PDT) Received: by mail-ed1-f54.google.com with SMTP id b8so22589602edk.2 for ; Thu, 07 Oct 2021 05:33:26 -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=FOCF5QIRrVffu4LCnL5j/k0yKOpkefFdKgayK8FlooE=; b=F/CoEHdgNnaa0UxJM/KG1lPY8IObVWFKU7XegxgPWvOo1HYT+LPgNxKXJs6wXPIkov xjPtGqFrDuMu0hn5WIh6gAPJ3Wftr5k5z/C1xOnOqXtU+NztQJ+rucPJ0L3Rrh4vPrmH hzcSu1JDy8UgdALr8bOwBCAoSt0nY5WMKgz2SXL76napmJD7OuKchzf754z4M8JUNIsh HWYZspvvn7Yq1Ye5PjATfsrUfKNfzdKL/xkolpjCwTujcgBXM7R/Tcp7wPQPS4D8HJqj o1T/7IR/L7ju+N3LvH0jspn+wrAp4VVxJFsgEKcSLRL22iwMeKshpleDErubm2+C1bYE SdIA== 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=FOCF5QIRrVffu4LCnL5j/k0yKOpkefFdKgayK8FlooE=; b=X/O3v+QdXk/fYxbkLR340F8wKSFfylJ1WGJesJg+sBkh1yIlIuTJcn69jDNa/Pt+KX nz2kdN2umeHbSL43qht3WHrEKeMwn6SNDtUxKm7nElFFpQf7GZc0GFATFPSJ2lAULF6p 3pQFd9UhginAn0IXmrSzMzvpcF5rwwmu5lobT8AFgzzW4woZ15fZryNqNi39jqhlbkPU 6pBYMxwTChIcALlMwTAcDyFnaGqFJobnSuhuzNttXIuYCOBXqVkzI+ddFPjd8at3fTgW 2h9TiV3vJjeiHZrPtgxBssfQzfLDvmkyBJkqDw2ja5a5BwcbG3PJeEtlvpacSfZrzgfd zNdQ== X-Gm-Message-State: AOAM533mGr49qsCA4Lyp1YOIG5wWyV6tkLgNKx7IYa5diZ0WteJvtr/G Jm13+MSRdxAXSh6XZRNQRx8herdnGDkSEM9Adv0V8vQZm/w= X-Google-Smtp-Source: ABdhPJx3r7pAokOOHCVoo9JIAP19q/1wvUwe82WEi/WGRiWEaDxnMrNz/eWmyweEGLJvYUHHASC+TbcvnBn5ojDT8FA= X-Received: by 2002:a05:6402:5191:: with SMTP id q17mr6115915edd.332.1633610003755; Thu, 07 Oct 2021 05:33:23 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 7 Oct 2021 21:33:12 +0900 Message-ID: To: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary="000000000000f9b6be05cdc277d9" Subject: Re: [PHP-DEV] [RFC] Random Extension 3.0 From: zeriyoshi@gmail.com (Go Kudo) --000000000000f9b6be05cdc277d9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I had misunderstood this for a long time. Now I understand. This is certainly something to think about. However, I think we also need to consider compatibility. How about something like the following? ```php : > 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 >> 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. >> > > 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 >>> the existing mt_rand() algorithm by retaining the same implementation f= or >>> mapping the raw random number stream into a range. However, the algorit= hm >>> we use for that is not exactly state of the art and requires two full-w= idth >>> 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?) bu= t it >>> would provide a different sequence than mt_rand(). Something we might w= ant >>> to consider. >>> >>> Regards, >>> Nikita >>> >> --000000000000f9b6be05cdc277d9--