[php-src] Issue #12434: Better name for method Randomizer::nextFloat()

From: Date: Sat, 14 Oct 2023 11:19:56 +0000
Subject: [php-src] Issue #12434: Better name for method Randomizer::nextFloat()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245565@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/12434 Author: dg ### Description I would like to suggest changing the name or removing the nextFloat() method. Now is ideal time before the stable release, then it would be too late of course. The name nextFloat() creates the expectation that it will return some other number in the generated series. See, for example, the following code: ```php $randomizer = new \Random\Randomizer(); $a = $randomizer->getFloat(100, 200); // number between 100..200 $b = $randomizer->nextFloat(); // another number between 100..200 ??? ``` Do you expect $b to be the next number in the interval 100..200? Surprisingly not, the method returns a number in the interval 0..1. Honestly, I don't understand the next prefix in the method name at all. Its [definition is](https://wiki.php.net/rfc/randomizer_additions#nextfloat): > This method is equivalent to ->getFloat(0, 1) That is, a function that returns a number in the interval 0..1 without any relation to anything previous. I therefore find the name completely misleading. A more accurate name would be, for example, getFloat0To1(), but I think that getFloat(0, 1) is obvious and there is no need to add a new method.

« previous php.bugs (#245565) next »