Re: RFC [Discussion]: Randomizer Additions

From: Date: Sat, 15 Oct 2022 09:19:43 +0000
Subject: Re: RFC [Discussion]: Randomizer Additions
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-118817@lists.php.net to get a copy of this message
Hi
For completeness, it would be good to have nextBool() as well.
I'm just wondering if that's really necessary. Generating a boolean is trivial with the nextFloat method (see example 1. Simulate a coinflip from the RFC).
No, IMO. Mathematically it doesn't really make sense and talking about floats, it will also be a very corner case not reached in tests that might happen in production rarely and break things.
Why does it not make mathematical sense? With the nextFloat method, I can understand the argument, because that is otherwise opaque, especially when you work with probabilities. With the getFloat method, however, I can imagine a few cases in which this makes sense. In our example, for example, we calculate a random longitude and latitude with the method. However, the value of Lat: +90.0 Lng: +180.0 cannot be generated, although it is a valid value. However, the value of Lat: -90.0 Lng: -180.0 is included. Am I missing something, or is there currently no simple mathematical way to implement this with an open-right interval?
I am having another small issue. As the Randomizer class is final, I guess this will not be perfectly polyfillable in userland. So... , if accepted, would it be completely wrong to have these new methods in PHP 8.2? What can it break?
I am relatively new and have little to no experience with contributing PHP functions, but I don't think this should be done. There is a good reason why this is not done and it only causes confusion if any functions are introduced after the feature freeze. In the end, however, I think it is the release manager who decides. Cheers Joshua Rüsweg

« previous php.internals (#118817) next »