rfc:random_extension_improvement
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:random_extension_improvement [2022/06/20 15:56] – drop combinedlcg zeriyoshi | rfc:random_extension_improvement [2022/07/22 09:55] (current) – reword two issues as the problem (VS the proposed solution) guilliamxavier | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== PHP RFC: Random Extension Improvement ====== | ====== PHP RFC: Random Extension Improvement ====== | ||
- | * Version: 1.3 | + | * Version: 1.5.4 |
* Date: 2022-06-16 | * Date: 2022-06-16 | ||
* Author: Go Kudo < | * Author: Go Kudo < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | There are several | + | Several |
- | + | ||
- | Key issues include: | + | |
==== Engine implementations are not final ==== | ==== Engine implementations are not final ==== | ||
- | The Random Extension has classes that are natively implemented as RNG engines, but they are not marked as final. | + | The Random Extension has classes that are natively implemented as RNG engines, but they are not marked as <php>final</ |
This allows classes to be created that inherit from native classes, but as stated in the previous RFC, user-implemented engines are inferior to native classes in terms of execution efficiency. This is true even for inheritance without method overrides, which often leads to confusion. | This allows classes to be created that inherit from native classes, but as stated in the previous RFC, user-implemented engines are inferior to native classes in terms of execution efficiency. This is true even for inheritance without method overrides, which often leads to confusion. | ||
- | The extension already provides a Random\Engine interface with a single generate(): string method. | + | The extension already provides a '' |
Even if the native classes are made final, it is easy for the user to create an alternative class using delegates. | Even if the native classes are made final, it is easy for the user to create an alternative class using delegates. | ||
This is clearly an API design error, and the native implementations of the interface should be marked as final. | This is clearly an API design error, and the native implementations of the interface should be marked as final. | ||
- | ==== CombinedLCG | + | ==== Random\SerializableEngine |
- | The newly added Random\Engine\CombinedLCG is only for use with PHP's lcg_value() function. | + | This interface is a remnant from when the < |
+ | |||
+ | For this reason, remove '' | ||
+ | |||
+ | This means that an Engine that implements SerializableEngine will no longer implement it. | ||
+ | However, serializability is determined by the implementation of the magic method in current PHP, so it has no effect. | ||
+ | |||
+ | ==== Random\Engine\CombinedLCG is low quality ==== | ||
+ | |||
+ | The newly added '' | ||
However, this algorithm is very classical and the quality of the output random numbers is at the lowest level. | However, this algorithm is very classical and the quality of the output random numbers is at the lowest level. | ||
In order to preserve the implementation of the lcg_value() function, the internal implementation is retained, but the implementation as a class is being dropped to prevent users from unintentionally using it. | In order to preserve the implementation of the lcg_value() function, the internal implementation is retained, but the implementation as a class is being dropped to prevent users from unintentionally using it. | ||
- | ==== Randomizer lacks array_rand() | + | ==== There is no equivalent of array_rand() ==== |
- | array_rand() uses RNG internally, but there is no alternative method in Randomizer. | + | <php>array_rand()</ |
As per the previous RFC, this was the intent, but upon further investigation, | As per the previous RFC, this was the intent, but upon further investigation, | ||
- | However, the name of the method | + | So add a method |
- | ==== "string" means a binary ==== | + | It may look incompatible with < |
- | In PHP, " | + | <code php> |
+ | $array = [' | ||
- | Therefore, it may be better to change the alternative method of str_shuffle(), Randomizer:: | + | // Before: |
+ | mt_srand(1234, MT_RAND_PHP); | ||
+ | $single = array_rand($array); // (int) 0 | ||
+ | $multiple = array_rand($array, 2); // (array) [1, 2] | ||
- | ==== PCG64 is ambiguous ==== | + | // After: |
+ | $engine | ||
+ | $randomizer | ||
+ | $single | ||
+ | // or: [$single] | ||
+ | $multiple | ||
+ | </ | ||
- | The Random Extension has implemented PCG64 as a new PRNG, but it is officially one variant of PCG64, oneseq-128-xsl-rr-64, | + | ==== " |
- | Therefore, change the class name from Random\Engine\PCG64 to Random\Engine\PCGOneseq128XslRr64. | + | In PHP, " |
- | ==== Mersenne Twister | + | Therefore, it may be better to change the alternative method of str_shuffle(), |
- | When PCG makes the choice to reflect a more detailed implementation in the name, Random\Engine\MersenneTwister is also an issue at the same time. | + | ==== Engine |
- | Random\Engine\MersenneTwister is precisely an implementation of the MT19937 | + | To clearly identify |
- | MT19937 also has an algorithm called MT19937_64 that generates 64-bit values. If for some reason MT19937_64 were to be implemented, | + | * '' |
+ | * '' | ||
==== PCG is not so famous ==== | ==== PCG is not so famous ==== | ||
PCG is a very good algorithm, boasting great randomness and performance. | PCG is a very good algorithm, boasting great randomness and performance. | ||
- | |||
However, I think its name recognition is in some ways inferior to Vigna' | However, I think its name recognition is in some ways inferior to Vigna' | ||
- | Therefore, I reimplement Xoshiro256**, | + | Therefore, I reimplement |
===== Proposal ===== | ===== Proposal ===== | ||
Line 68: | Line 85: | ||
For each of these issues, we will create a ballot option and make a decision. | For each of these issues, we will create a ballot option and make a decision. | ||
- | ==== CombinedLCG is outdated | + | ==== Engine implementations are not final ==== |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
</ | </ | ||
- | ==== Engine implementations are not final ==== | + | ==== Random\SerializableEngine is not useful |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
</ | </ | ||
- | ==== Randomizer lacks array_rand() replacement method | + | ==== Random\Engine\CombinedLCG is low quality |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
</ | </ | ||
- | ==== " | + | ==== There is no equivalent of array_rand() |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
</ | </ | ||
- | ==== PCG64 is ambiguous | + | ==== " |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
</ | </ | ||
- | ==== Mersenne Twister is ambiguous | + | ==== Engine classnames are not precise |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
Line 112: | Line 129: | ||
==== PCG is not so famous ==== | ==== PCG is not so famous ==== | ||
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
Line 119: | Line 136: | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
- | The following names have been reserved and will no longer be available | + | The following names have been reserved and will no longer be available: |
+ | |||
+ | * Random\Engine\Mt19937 | ||
+ | * Random\Engine\PcgOneseq128XslRr64 | ||
+ | * Random\Engine\Xoshiro256StarStar | ||
+ | |||
+ | The following class names will be made available again: | ||
- | * Random\Engine\PCGOneseq128XslRr64 | + | * Random\Engine\CombinedLCG |
- | * Random\Engine\Xoshiro256StarStar (optional) | + | * Random\Engine\MersenneTwister |
- | * Random\Engine\MT19937 | + | * Random\Engine\PCG64 |
+ | * Random\SerializableEngine | ||
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== | ||
Line 145: | Line 169: | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | currently none | + | * https:// |
===== References ===== | ===== References ===== | ||
* https:// | * https:// |
rfc/random_extension_improvement.txt · Last modified: 2022/07/22 09:55 by guilliamxavier