Re: [RFC] [Draft] Add Randomizer class (before: Add RNG extension)

From: Date: Mon, 31 May 2021 14:04:14 +0000
Subject: Re: [RFC] [Draft] Add Randomizer class (before: Add RNG extension)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-114678@lists.php.net to get a copy of this message
Hi Internals. I apologize for the discussion outside the ML. Here's a brief history. https://github.com/php/php-src/pull/7079 - To test the implementation, I sent a Pull-Request to php-src on GitHub. - An excellent point was made, and we ended up having a discussion about it on GitHub. - I was going to change the current implementation RFC to Under Discussion, but decided against it. Also, sorry for the delay in answering your questions. I am not very good at English and it is taking me a long time. The current implementation and RFC: - https://github.com/php/php-src/pull/7079 - https://wiki.php.net/rfc/rng_extension However, the implementation of this user-defined class is very ugly and we intend to improve it as follows. Before: ```php class Random { public function __construct(string $algo = RANDOM_XORSHIFT128PLUS, ?int $seed = null) {} //.... } class UserDefinedRandom extends Random { protected function next(): int { return 1; } } ``` After: ```php interface RandomNumberGenerator { public function generate(): int; } final class Random { public function __construct(string|RandomNumberGenerator $algo = RANDOM_XORSHIFT128PLUS, ?int $seed = null) {} } ``` 2021å¹´5月26æ—¥(æ°´) 0:35 Go Kudo <zeriyoshi@gmail..com>: > Hi, Thanks for the response. > > The RFC has been revised based on the points you pointed out. > > https://wiki.php.net/rfc/rng_extension > > The main changes are as follows: > > - Class name has been changed from Randomizer to �|S�§ÔéÎã > ©Œ6}Random . > - Added a static method getNonBiasedMax() to get the safe > range. > - int() and bytes() have been > renamed to getInt() and getBytes() > for avoid future reserved words. > - getInt() arguments no longer accept null. > - shuffle(array|string $target): array|string has been > separated into > arrayShuffle(array $array) and > stringShuffle(string $string): string > for more comfortable static-analysis. > - fix: php_random_algo struct (included uint64_t -> int64_t) > > Answer a few questions: > > > When $seed is null, what is used for the seed value? > > Depends on the algo's implementation, but basically it is using internal > php_random_int(). > It is similar to mt_srand() on PHP 8.1. > > > > https://github.com/php/php-src/commit/53ee3f7f897f7ee33a4c45210014648043386e13 > > > Why cancelled RNG Extension? > > As a result of discussions during the draft, the functions became a single > class and no longer need to be separated. The functionality for random > numbers is now included in ext/standard and will conform to this. (e.g. > rand.c random.c) > > > Deprecation > > Dropped in the last RFC update. > These were premature and should not have been included with the RFCs that > add new features. > > If the direction seems generally okay, I'd like to start implementing it > to show more details. > > Regards, > Go Kudo > > 2021å¹´5月23æ—¥(æ—¥) 5:56 Go Kudo <zeriyoshi@gmail.com>: > >> Hi, Internals and all participated in the previous discussion. >> >> RFCs have been cleaned up and the proposal has been substantially changed. >> >> https://wiki.php.net/rfc/rng_extension >> >> First of all, I apologize for not checking out the implementation of >> password_hash(), which is a precedent to learn from. >> >> I think I've answered all the questions I've been getting on Open Issues.. >> If I have left anything out, please let me know. >> >> Regards, >> Go Kudo >> >

« previous php.internals (#114678) next »