rfc:improve_predictable_prng_random
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:improve_predictable_prng_random [2017/02/03 04:34] – Fix function signature yohgaki | rfc:improve_predictable_prng_random [2018/03/01 23:13] (current) – RFC is Under Discussion carusogabriel | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2017-02-01 | * Date: 2017-02-01 | ||
* Author: Yasuo Ohgaki < | * Author: Yasuo Ohgaki < | ||
- | * Status: | + | * Status: |
* First Published at: http:// | * First Published at: http:// | ||
Line 105: | Line 105: | ||
public function getBytes(int $length); // Raw bytes | public function getBytes(int $length); // Raw bytes | ||
public function getString(int $length, int $bits = 6); // String [0-9a-zA-Z, | public function getString(int $length, int $bits = 6); // String [0-9a-zA-Z, | ||
- | public function seed($seed = NULL); // No use with CS RNG, return TRUE always. | + | public function seed($seed = NULL); // No use with CS RNG, raise exception. |
- | public function getState(); // Return string representation PRNG state. No use with CS RNG, return NULL. | + | public function getState(); // Return string representation PRNG state. No use with CS RNG, raise exception. |
- | public function setState(string $state); // Set PRNG state. No use with CS RNG, return TRUE always. | + | public function setState(string $state); // Set PRNG state. No use with CS RNG, raise exception. |
- | public function getCount(); // No use with CS RNG, return 0 always. | + | public function getCount(); // No use with CS RNG, raise exception. |
- | public function getReseedCycle(); | + | public function getReseedCycle(); |
- | public function setReseedCycle(int $count); // No use with CS RNG, return TRUE always. | + | public function setReseedCycle(int $count); // No use with CS RNG, raise exception. |
} | } | ||
Line 130: | Line 130: | ||
public function __construct($seed = NULL) { | public function __construct($seed = NULL) { | ||
$this-> | $this-> | ||
+ | } | ||
+ | |||
+ | private reseed() { | ||
+ | $this-> | ||
+ | if ($this-> | ||
+ | $this-> | ||
+ | $this-> | ||
+ | } | ||
} | } | ||
| | ||
public function getInt($min = NULL, $max = NULL) { | public function getInt($min = NULL, $max = NULL) { | ||
assert($min <= $max); | assert($min <= $max); | ||
+ | $this-> | ||
if ($min && $max) { | if ($min && $max) { | ||
return mt_rand($min, | return mt_rand($min, | ||
Line 149: | Line 158: | ||
| | ||
public function getBytes(int $length) { | public function getBytes(int $length) { | ||
- | // Return raw random bytes | + | // Return raw random bytes. 3 out of 4 bytes are used not to disclose full PRNG state |
} | } | ||
| | ||
Line 163: | Line 172: | ||
// Update state by user seed | // Update state by user seed | ||
mt_srand($seed); | mt_srand($seed); | ||
+ | $this-> | ||
} else { | } else { | ||
// Seed by system generated random value | // Seed by system generated random value | ||
Line 209: | Line 219: | ||
</ | </ | ||
- | uint32_t BG(mt_rand_is_seeded) is used for already seeded flag and counter. | + | uint32_t BG(mt_rand_is_seeded) is used for already seeded flag and counter. |
Line 217: | Line 227: | ||
mt_srand()/ | mt_srand()/ | ||
- | If users want static random values, they have to use RandomStatus | + | If users want static random values, they have to use Random |
===== Proposed PHP Version(s) ===== | ===== Proposed PHP Version(s) ===== |
rfc/improve_predictable_prng_random.1486096459.txt.gz · Last modified: 2017/09/22 13:28 (external edit)