Random\Engine\Xoshiro256StarStar::__construct
(PHP 8 >= 8.2.0)
Random\Engine\Xoshiro256StarStar::__construct — Constructs a new xoshiro256** engine
Descrição
Warning
Esta função não está documentada; apenas a lista de argumentos está disponível.
Parâmetros
seed
-
How the internal 256 bit (32 byte) state consisting of four unsigned 64 bit integers is seeded depends on the type used as the
seed
.Type Descrição null Fills the state with 32 random bytes generated using the CSPRNG. int Fills the state with four consecutive values generated with the SplitMix64 algorithm that was seeded with seed
interpreted as an unsigned 64 bit integer.string Fills the state by interpreting a 32 byte string as four little-endian unsigned 64 bit integers.
Erros/Exceções
-
If the length of a string
seed
is not 32 bytes, a ValueError will be thrown. -
If a string
seed
consists of 32 NUL bytes ("\x00"
), a ValueError will be thrown.
Exemplos
Example #1 Random\Engine\Xoshiro256StarStar::__construct() example
<?php
// Uses a random 256 Bit seed.
$e = new \Random\Engine\Xoshiro256StarStar();
$r = new \Random\Randomizer($e);
?>
Example #2 Deriving a seed from a string
<?php
$string = "My string seed";
// Hash the string with SHA-256 using binary output to turn the
// $string into a 256 Bit seed. Using the same string will result
// in the same sequence of randomness.
$e = new \Random\Engine\Xoshiro256StarStar(
hash('sha256', $string, binary: true)
);
echo bin2hex($e->generate()), "\n";
?>
O exemplo acima produzirá:
6e013453678388c2