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 16:06] – remove SerializableEngine 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.4 | + | * 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. | ||
- | ==== Randomizer lacks array_rand() replacement method | + | ==== Random\SerializableEngine is not useful |
- | array_rand() uses RNG internally, but there is no alternative method | + | This interface is a remnant from when the < |
- | As per the previous RFC, this was the intent, but upon further investigation, | + | |
- | However, the name of the method may need to be reconsidered. How about Randomizer:: | + | 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. | ||
- | In PHP, " | + | ==== Random\Engine\CombinedLCG |
- | Therefore, it may be better to change the alternative method of str_shuffle(), Randomizer:: | + | The newly added '' |
+ | However, this algorithm | ||
- | ==== PCG64 is ambiguous ==== | + | In order to preserve the implementation of the lcg_value() function, the internal implementation |
- | The Random Extension has implemented PCG64 as a new PRNG, but it is officially one variant | + | ==== There is no equivalent |
- | Therefore, change | + | < |
+ | As per the previous RFC, this was the intent, but upon further investigation, | ||
- | ==== Mersenne Twister is ambiguous ==== | + | So add a method < |
- | 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. | + | It may look incompatible with < |
- | Random\Engine\MersenneTwister is precisely an implementation of the MT19937 algorithm. | + | <code php> |
+ | $array = [' | ||
- | MT19937 also has an algorithm called MT19937_64 that generates 64-bit values. If for some reason MT19937_64 were to be implemented, the fact that the name Mersenne Twister is already in use could be problematic. | + | // Before: |
+ | mt_srand(1234, MT_RAND_PHP); | ||
+ | $single = array_rand($array); | ||
+ | $multiple = array_rand($array, | ||
- | ==== PCG is not so famous ==== | + | // After: |
+ | $engine | ||
+ | $randomizer | ||
+ | $single | ||
+ | // or: [$single] | ||
+ | $multiple | ||
+ | </ | ||
- | PCG is a very good algorithm, boasting great randomness and performance. | + | ==== " |
- | However, I think its name recognition | + | In PHP, " |
- | Therefore, | + | Therefore, |
- | ==== CombinedLCG is outdated | + | ==== Engine classnames are not precise |
- | The newly added Random\Engine\CombinedLCG is only for use with PHP's lcg_value() function. | + | To clearly identify the implemented algorithm, the PCG64 and MersenneTwister engines should be renamed to their canonical upstream name: |
- | However, this algorithm is very classical | + | |
- | 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. | + | * '' |
+ | * '' | ||
- | ==== Random\SerializableEngine | + | ==== PCG is not so famous |
- | This interface | + | PCG is a very good algorithm, boasting great randomness and performance. |
+ | However, I think its name recognition | ||
- | For this reason, remove RandomEngine\SerializableEngine. | + | Therefore, I reimplement %%Xoshiro256**%%, |
===== Proposal ===== | ===== Proposal ===== | ||
Line 76: | Line 87: | ||
==== Engine implementations are not final ==== | ==== Engine implementations are not final ==== | ||
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
</ | </ | ||
- | ==== Randomizer lacks array_rand() replacement method | + | ==== Random\SerializableEngine is not useful |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
</ | </ | ||
- | ==== " | + | ==== Random\Engine\CombinedLCG is low quality |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
</ | </ | ||
- | ==== PCG64 is ambiguous | + | ==== There is no equivalent of array_rand() |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
</ | </ | ||
- | ==== Mersenne Twister is ambiguous | + | ==== " |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
</ | </ | ||
- | ==== PCG is not so famous | + | ==== Engine classnames are not precise |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
</ | </ | ||
- | ==== CombinedLCG | + | ==== PCG is not so famous |
- | + | ||
- | <doodle title=" | + | |
- | * Yes | + | |
- | * No | + | |
- | </ | + | |
- | + | ||
- | ==== Random\SerializableEngine is outdated | + | |
- | <doodle title=" | + | <doodle title=" |
* Yes | * Yes | ||
* No | * No | ||
Line 134: | Line 138: | ||
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\PCGOneseq128XslRr64 | + | * Random\Engine\Mt19937 |
+ | * Random\Engine\PcgOneseq128XslRr64 | ||
* Random\Engine\Xoshiro256StarStar | * Random\Engine\Xoshiro256StarStar | ||
- | * Random\Engine\MT19937 | ||
The following class names will be made available again: | The following class names will be made available again: | ||
* Random\Engine\CombinedLCG | * Random\Engine\CombinedLCG | ||
+ | * Random\Engine\MersenneTwister | ||
+ | * Random\Engine\PCG64 | ||
* Random\SerializableEngine | * Random\SerializableEngine | ||
Line 163: | Line 169: | ||
===== Patches and Tests ===== | ===== Patches and Tests ===== | ||
- | currently none | + | * https:// |
===== References ===== | ===== References ===== | ||
* https:// | * https:// |
rfc/random_extension_improvement.1655741218.txt.gz · Last modified: 2022/06/20 16:06 by zeriyoshi