rfc:rng_extension

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rfc:rng_extension [2021/09/03 13:53]
zeriyoshi fix: missing CSPRNG functions.
rfc:rng_extension [2021/09/03 14:28] (current)
zeriyoshi
Line 90: 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("foobar"); // shuffle string
 +$arr = range(1, 10);
 +shuffle($arr); // shuffle array items (pass by reference)
 +
 +// object
 +$mt = new Random\NumberGenerator\MT19937(1234);
 +$mt->generate(); // generate random number 
 +$random = new Random($mt);
 +$random->getInt(1, 10); // generate random number in range
 +$random->shuffleString("foobar"); // shuffle string
 +$random->shuffleArray(range(1, 10)); // shuffle array items (pass by value)
 +</code>
  
 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 188: 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(), and array_rand().+  * Changes random source to php_random_int() shuffle(), str_shuffle(), and array_rand() .
   * Deprecate srand() and mt_srand() (step by step)   * Deprecate srand() and mt_srand() (step by step)
  
rfc/rng_extension.1630677239.txt.gz · Last modified: 2021/09/03 13:53 by zeriyoshi