PHP 8.4.2 Released!

Random\Engine\Xoshiro256StarStar::__construct

(PHP 8 >= 8.2.0)

Random\Engine\Xoshiro256StarStar::__constructConstructs a new xoshiro256** engine

说明

public Random\Engine\Xoshiro256StarStar::__construct(string|int|null $seed = null)

警告

本函数还未编写文档,仅有参数列表。

参数

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 说明
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.

错误/异常

示例

示例 #1 Random\Engine\Xoshiro256StarStar::__construct() example

<?php
// Uses a random 256 Bit seed.
$e = new \Random\Engine\Xoshiro256StarStar();

$r = new \Random\Randomizer($e);
?>

示例 #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";
?>

以上示例会输出:

6e013453678388c2
添加备注

用户贡献的备注

此页面尚无用户贡献的备注。
To Top