Re: [RFC] Object-scope RNG implementation

From: Date: Mon, 25 Jan 2021 01:05:53 +0000
Subject: Re: [RFC] Object-scope RNG implementation
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-112978@lists.php.net to get a copy of this message
Hi internals. RFC has been updated to 1.3 and implemented. https://wiki.php.net/rfc/object_scope_prng The main changes are as follows: - RNG\OSRNG has been renamed to RNG\OS. This was too verbose. - rng_rand() has been renamed to rng_int() and the arguments $min and $max are now required. - RNG\RNG64Interface has been removed and next64() is now included in RNGInterface. - PHP code does not depend on the size of int. Even if it contains a 64-bit implementation, it will work fine on 32-bit PHP. Libraries should always consider the 64-bit environment. - To solve various problems, the rng_next() and rng_next64() functions have been added. - rng_next64() throws a ValueError exception when called in a 32bit environment. The current phpstub is as follows: ```php function shuffle(array &$array, ?RNG\RNGInterface $rng = null): bool {} function str_shuffle(string $string, ?RNG\RNGInterface $rng = null): string {} function array_rand(array $array, int $num = 1, ?RNG\RNGInterface $rng = null): int|string|array {} function rng_bytes(RNG\RNGInterface $rng, int $length): string {} function rng_int(RNG\RNGInterface $rng, int $min, int $max): int {} function rng_next(RNG\RNGInterface $rng, bool $unsigned = true): int {} /** @throws ValueError */ function rng_next64(RNG\RNGInterface $rng, bool $unsigned = true): int {} ``` On the other hand, there are still the following problems - If next64() method is called directly in a 32-bit environment, it will produce unintended results. - This can be avoided by using rng_next64() in RFC 1.3. As with the various internal interfaces, direct method calls can be deprecated. - Namespace. RNG, PHP\RNG... etc - Interface naming. RNGInterface may be a bit redundant. NumberGenerator, etc? We are looking for feedback on these problems. Regards, Go Kudo 2021年1月9日(土) 19:00 Go Kudo <zeriyoshi@gmail..com>: > Hi internals. > > I think I'm ready to discuss this RFC. > https://wiki.php.net/rfc/object_scope_prng > > Previous internals thread: https://externals.io/message/112525 > > Now is the time to let me know what you think. > > Regards, > Go Kudo >

« previous php.internals (#112978) next »