On Tue, May 11, 2021, at 7:57 AM, Go Kudo wrote: > Hi internals. > > I previously proposed an object scope RNG implementation inside. > However, the RFC was rejected after a vote. > > https://wiki.php.net/rfc/object_scope_prng > > Vote: https://externals.io/message/113888 > Discussion: https://externals.io/message/112819 > > As per my previous proposal, PHP is currently in a very unclear state > regarding the random number implementation. > > So I would like to ask a few questions. > > - Do you think that PHP needs an object-scoped random number > implementation? And why?
I don't work in areas that would tend to need such a thing, but other people do so I have no objection to it existing, as long as it's well-designed. > - If the API in the previous RFC was improved and voted on again, would you > be willing to vote for it? Yes. > - What issues do you think should have been resolved between proposal and > ballot in the previous RFC? > > I would like a variety of opinions. 1) Get rid of all of the functions. Object-scoped means... you just have an object with methods on it. That's it. 2) Don't force people to use a subclass with an incomprehensible name. In this case, a single class with a constructor parameter that specifies the algorithm to use is far superior. Possibly that parameter could be an object conforming to an interface if you really want, as long as the default is reasonable so most people never have to use it. 3) Perhaps it should be named RandomSequence or similar? It's not truly generating random numbers. It's generating a repeatable but difficult to produce sequence off of a seed value. That's not the same thing as random_int() et al. So, at first pass, an API could be as simple as (pseudocode): class RandomSequence { public function __construct(int $seed = time(), $algorithm = 'some_default') { ... } public function next(): int { ... } } And that's it. That's nice and simple and predictable to use. 4) As Levi said, we have a new policy document on namespace usage. This is a good first application of it. --Larry Garfield -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php