Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114682 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60974 invoked from network); 1 Jun 2021 14:15:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Jun 2021 14:15:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 77D841804AE for ; Tue, 1 Jun 2021 07:28:19 -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-Virus: No X-Envelope-From: Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 ; Tue, 1 Jun 2021 07:28:18 -0700 (PDT) Received: by mail-ed1-f50.google.com with SMTP id r11so17555008edt.13 for ; Tue, 01 Jun 2021 07:28:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=CyBMDigIhQ9tiRuT9rxWOzOR48ObZrBBHlriL0S4vTM=; b=F36M137i+oLir/EaIbmrrgf8gtFZlxmlAnqeK53noJCrBTFqTWS7EPx77bjAQEjRmd Zxy9ycRN98UBsCCEB6a2JNRrxFWWTy8qjiSyKUMM7ERarcGvmaQvR4y231PQ+gND6KGC G6s7OWUcekBU/hoaeiz6EvRobQ1QnWUA+Vl+c8ea5xIsLnDh7n+oIxH5szBnYbX2EpvR cTfWIQKZu0XU/JrpnQYG18JyEiUWIVIpsH0gKh5M9uIXcn+DiarJ5ECwaDuRAxQ2zNVa /rN9OW8Opb31E7mbF6Myln5zCpm8RW0IECUkSUaF419ST/h6xSgvBPSe8csSZEEw9IXa Sx9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=CyBMDigIhQ9tiRuT9rxWOzOR48ObZrBBHlriL0S4vTM=; b=HbSSU42M8yei5y01jZCxcvqI1yg9GB8Sbkz2Z3LrEv4GZTHsW78JblpmypGpx+kWZB CqM9yOSIB+g9v9tVgX2Ak3xJEXem2fLG38HbyxasnBjhT7yFipFrNN3rV9j9WwHv8+le vpry79sHfeGbdTnGygo3WRGrGPCqrL7PeNgrXbWb7q+vLMDfXM3L8vNZokRVLxstxrB5 2WuX1tIlS/npaSnNWp58+Um0o7ZraiUhkvOWowGiE+WJg+poUFYSOZTaRmz8ZOglrfsL XvFmPICcrp4Ve4yHSYDLW20drP6UwXOCdkd7WcTB9b8OiADhe60KEaTh1ZmhPBhworSS TyUw== X-Gm-Message-State: AOAM532L3XmmsPXdmWeFuZO8XbMz5pOhpj5yzVdQ81FHEjVvMFznZTna D0zPHRj8fsN76ZLt5UF8dujGYDEoOxDE9UItjW1VrIqGGNmp/MTn X-Google-Smtp-Source: ABdhPJxLLVc9tSe7EV/Y2RG9NfjxPOECDcNCbhNsNCe06Yb1wPiQplHdS5aN/8+KnZjSYXqqkHQCIYGhi4V06ZyFppQ= X-Received: by 2002:a50:fb8f:: with SMTP id e15mr5324777edq.46.1622557696345; Tue, 01 Jun 2021 07:28:16 -0700 (PDT) MIME-Version: 1.0 Date: Tue, 1 Jun 2021 23:28:05 +0900 Message-ID: To: PHP internals Cc: Nikita Popov , Guilliam Xavier , Dan Ackroyd , Kamil Tekiela , Rowan Tommins , =?UTF-8?Q?Alexandru_P=C4=83tr=C4=83nescu?= Content-Type: multipart/alternative; boundary="0000000000001e484405c3b52751" Subject: [RFC] Under Discussion: Add Random class and RandomNumberGenerator interface From: zeriyoshi@gmail.com (Go Kudo) --0000000000001e484405c3b52751 Content-Type: text/plain; charset="UTF-8" Hello internals. Thanks for continuing to participate in the discussion. I've sorted out the proposal, and finished writing and implementing the RFC. (Funny, I know.) I think it's time to start a discussion. https://wiki.php.net/rfc/rng_extension https://github.com/php/php-src/pull/7079 The main changes since last time are as follows: - The ugly RANDOM_USER has been removed. - RandomNumberGenerator interface has been added for user-defined RNGs. - Random class is now final. - Random class now accepts a RandomNumberGenerator interface other than string as the first argument to the constructor. - INI directive has been removed. In 32-bit environments, the result is always truncated. What I'm struggling with now is the behavior when calling nextInt() in a 32-bit environment using a 64-bit RNG. It currently returns a truncated result, which means that the code loses compatibility with the result of running on a 64-bit machine. I was also considering throwing an exception, but which would be preferable? I would like to answer a few unanswered questions. > What is bias? I' ve confirmed that the bias issue in mt_rand has already been fixed and is no longer a problem. This implementation copies most of it from mt_rand. Therefore, this problem does not exist. Therefore, an equivalent method to mt_getrandmax() is no longer provided. > uint64 & right-shift This is a specification of the RNG implementation. PHP does not have unsigned integers, but RNG handles unsigned integers (to be precise, even the sign bit is random). As mentioned above, PHP does not have unsigned integers, which means that using the results generated by RNGs may cause compatibility problems in the future. To avoid this, a 1-bit right shift is always required (similar to mt_rand()). --0000000000001e484405c3b52751--