Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:119190 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 31931 invoked from network); 20 Dec 2022 08:15:46 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Dec 2022 08:15:46 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5FD6018033A for ; Tue, 20 Dec 2022 00:15:45 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 20 Dec 2022 00:15:44 -0800 (PST) Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-43ea87d0797so131721637b3.5 for ; Tue, 20 Dec 2022 00:15:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=zpX7UKtsoDzCjqABhF5qAcCxlzHU3gZ/XSbFnJh2cc8=; b=QCzL8V7UMbwusUq2iY1fRJJoRZMd+MDz2TRtaZ6y0+s0YGfLRSrn5va7a6Je/CfuoS VN1tR5iYz08KpBBwcWpgmJzn+aAT34LEX8CLVJlGvpuNDMv5IkMDwTHNtFDBVinpJKcl C1oP6sEbgj9wtdZi5ArwLHKXrpEd28v+a6CYAlosv5+hsiv8wfgMle4zJN8RM/euk9rT pWwcwH7eAF+3+aHHp+19DC/npowNMFzwoX/XtmTnCMniu7oFXaZJXoWkqpeTYz9mFCMp RG3fDe8HCQXs8SZ3aBwb/EkQLLXdnbmMJ82CUiBRxsFeAT0DbnhhsJjWHByJF6Rvobkq IGfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zpX7UKtsoDzCjqABhF5qAcCxlzHU3gZ/XSbFnJh2cc8=; b=YJ36Wb1M9pvv+JrBpdorMF8fZm4ukKKbVc1Vg1LhR9Hnx4WmAPzEJk4wqkY/jtNQRD Bba2EN0DbUd2Pq4TI2giu0iTHBr6pnQ5hlGjNp5yGPTvXBNTfDMUpobavm+WUbE0oLXp ja1IrWiJ8HVQR+ZpgZrDgA+6RHVvAqu48GHieRd4BMr/yhhlAwY9TtyEIhGUzCZesFks J5G+aJSYysf+abVIFfW4Z0P2eRD7w8VelSxIotowH15fC/aIMDac6D8zZfuVXKC1lbKf RZz8Jgvcc5S6CIj5YEkKwfLOCWC8j1NdI6NfMiBjHkg6Fz3q+Q4aYs0PWLpbM3xa8vBR hm9g== X-Gm-Message-State: ANoB5pky9z5lJWxGUGIu6AbPLKx9XvLigp5ZoitCawntfvxOH6Tjo+Gj wqgePY9DsSAdGZevtDwckPEz6rnqChqiYYiGJ84= X-Google-Smtp-Source: AA0mqf55rMsBfauNQBN3N1M9zlfki2Fg276aT1mB8ENhhvzzThe1Ke3+OqQfc8KilRW0yzJbIbKhbm6xjSihDcKVAu0= X-Received: by 2002:a81:cf05:0:b0:407:ab77:ec7d with SMTP id u5-20020a81cf05000000b00407ab77ec7dmr6337138ywi.40.1671524144255; Tue, 20 Dec 2022 00:15:44 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 20 Dec 2022 09:15:07 +0100 Message-ID: To: Go Kudo Cc: internals@lists.php.net, =?UTF-8?Q?Tim_D=C3=BCsterhus?= Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] ext-random: add random_float() ? From: divinity76@gmail.com (Hans Henrik Bergan) btw while we're on the topic, does anyone know if this function gives biased results/is-safe or not? i honestly don't know: function random_float(float $min, float $max): float { if ($min > $max) throw new \InvalidArgumentException("min must be less than max"); if ($min === $max) return $min; return $min + random_int(0, PHP_INT_MAX) / PHP_INT_MAX * ($max - $min); } On Tue, 20 Dec 2022 at 09:06, Hans Henrik Bergan wrote: > > >returns a value between 0.0 and 1.0. > > wouldn't it be better to follow random_int(int $min, int $max) design? eg > random_float(float $min, float $max): float > > On Tue, 20 Dec 2022 at 07:27, Go Kudo wrote: > > > > Hi Internals. > > > > Congratulations on the release of PHP 8.2. > > I just recently upgraded production PHP from 7.4 to 8.1 :) > > > > Now that my work is done, I was thinking about a proposal for a sunsetting > > of existing functions for PHP 8.3 based on the features introduced in > > ext-random, and I realized that there is no alternative to `lcg_value()`. > > > > Essentially, this could be completely replaced by > > Random\Randomizer::getFloat(), but there are easier `random_int()` and > > `random_bytes()` functions for ints and strings. > > > > The Randomizer may be overkill and complicated for PHP use cases where > > random number reproducibility is not required in many cases. > > > > So, why not add a `random_float(): float` function? This function, like the > > others, uses CSPRNG and returns a value between 0.0 and 1.0. This behavior > > is `Closed` `Closed`. > > > > Opinions are welcome. > > > > Regards, > > Go Kudo