Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121331 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 16796 invoked from network); 16 Oct 2023 08:34:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 16 Oct 2023 08:34:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4617D180044 for ; Mon, 16 Oct 2023 01:34:44 -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=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15623 212.45.192.0/19 X-Spam-Virus: No X-Envelope-From: Received: from mail.gna.ch (mail.gna.ch [212.45.196.109]) (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 ; Mon, 16 Oct 2023 01:34:43 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by darkcity.gna.ch (Postfix) with ESMTP id D9C4F3A0A3B for ; Mon, 16 Oct 2023 10:34:41 +0200 (CEST) X-Virus-Scanned: amavisd-new at example.com Received: from mail.gna.ch ([127.0.0.1]) by localhost (darkcity.gna.ch [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XW_cD7QJHd2q for ; Mon, 16 Oct 2023 10:34:41 +0200 (CEST) Received: from smtpclient.apple (unknown [IPv6:2a02:1210:2ea4:cf00:8904:86f8:92c3:ce32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by darkcity.gna.ch (Postfix) with ESMTPSA id 6320C3A07D9 for ; Mon, 16 Oct 2023 10:34:41 +0200 (CEST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.100.2.1.4\)) Date: Mon, 16 Oct 2023 10:34:41 +0200 References: To: PHP internals In-Reply-To: Message-ID: X-Mailer: Apple Mail (2.3774.100.2.1.4) Subject: Re: [PHP-DEV] Better name for method Randomizer::nextFloat() From: cschneid@cschneid.com (Christian Schneider) Am 15.10.2023 um 19:24 schrieb Tim D=C3=BCsterhus : > Making getFloat(float $min =3D 0.0, float $max =3D 1.0, = IntervalBoundary $boundary =3D IntervalBoundary::ClosedOpen) would = seemingly make it legal to call ->getFloat(0.5), which I consider to be = worse than nextFloat(). While I understand that you find getFloat(0.5) undesirable I would not = consider it illegal, e.g. getFloat(max:5). Additionally I would consider getInt(max:100) to be a very valid usage = too. > Side note: The implementation of nextFloat() is much more efficient = than that of getFloat(0.0, 1.0) and the output will differ even for the = same seeded engine. The domain of legal return values is identical. This sounds like an implementation detail as I'm pretty sure you could = switch to that fast path easily enough if neither of the arguments were = given. Side-note: The case of nextInt() is a bit trickier and strikes me as a = bit of a weird API and I'd consider dropping it too: Having the max = value depend on the Randomizer engine makes the generated values = unstable in regards to switch the Engine. And if I read the = documentation correctly then it only generates 32 bit values (or should = it be 31 bits as it returns positive values only?). I think it would be = clearer to require the Engine to provide at least 4 bytes and then = specify the default max value of getInt() to be 2^31, optionally = overridable with something up to PHP_INT_MAX. So in summary I'd support both adding default values to = getInt()/getFloat() as well as dropping nextFloat() in favor of = getFloat() (and possible nextInt() with getInt()).=20 Regards, - Chris