Random\Engine\Xoshiro256StarStar::__construct
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.2.0)
Constructs a new xoshiro256** engine
Description
Random\Engine\Xoshiro256StarStar::__construct(string|int|null $seed = null)
Parameters
seedHow 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 Description nullFills the state with 32 random bytes generated using the CSPRNG. intFills the state with four consecutive values generated with the SplitMix64 algorithm that was seeded with seedinterpreted as an unsigned 64 bit integer.stringFills the state by interpreting a 32 byte stringas four little-endian unsigned 64 bit integers.
Errors/Exceptions
- If the length of a
stringseedis not 32 bytes, aValueErrorwill be thrown. - If a
stringseedconsists of 32 NUL bytes ("\x00"), aValueErrorwill be thrown.
Examples
Random\Engine\Xoshiro256StarStar::__construct() example
php
<?php
// Uses a random 256 Bit seed.
$e = new \Random\Engine\Xoshiro256StarStar();
$r = new \Random\Randomizer($e);
?>Deriving a seed from a String
php
<?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";
?>The above example will output:
output
6e013453678388c2