rfc:rng_extension
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
rfc:rng_extension [2021/09/02 15:06] zeriyoshi 3.0 |
rfc:rng_extension [2021/09/03 14:28] zeriyoshi |
||
---|---|---|---|
Line 54: | Line 54: | ||
* mt_srand() | * mt_srand() | ||
* mt_rand() | * mt_rand() | ||
+ | * random_int() | ||
+ | * random_bytes() | ||
At the same time, the following internal APIs will also be relocated. If you want to use them, you can simply include ext/ | At the same time, the following internal APIs will also be relocated. If you want to use them, you can simply include ext/ | ||
Line 88: | Line 90: | ||
* shuffleArray() | * shuffleArray() | ||
* shuffleString() | * shuffleString() | ||
+ | |||
+ | This class can be used in the following way. | ||
+ | |||
+ | <code php> | ||
+ | // functions | ||
+ | mt_srand(1234); | ||
+ | mt_rand(); // generate random number | ||
+ | mt_rand(1, 10); // generate random number in range | ||
+ | str_shuffle(" | ||
+ | $arr = range(1, 10); | ||
+ | shuffle($arr); | ||
+ | |||
+ | // object | ||
+ | $mt = new Random\NumberGenerator\MT19937(1234); | ||
+ | $mt-> | ||
+ | $random = new Random($mt); | ||
+ | $random-> | ||
+ | $random-> | ||
+ | $random-> | ||
+ | </ | ||
The Random class accepts an instance that inherits from Random\NumberGenerator as a constructor argument. | The Random class accepts an instance that inherits from Random\NumberGenerator as a constructor argument. | ||
Line 186: | Line 208: | ||
* Replace the state of the existing implementation with php_random_ng. | * Replace the state of the existing implementation with php_random_ng. | ||
- | * Replace random_bytes() with random_bytes() for random numbers used in shuffle(), str_shuffle(), | + | * Changes random source to php_random_int() a shuffle(), str_shuffle(), |
* Deprecate srand() and mt_srand() (step by step) | * Deprecate srand() and mt_srand() (step by step) | ||
rfc/rng_extension.txt · Last modified: 2022/06/28 02:36 by zeriyoshi