大网数据广告活动
PHP 语言与运行手册

Random\Engine\Xoshiro256StarStar::__construct · Constructs a new xoshiro256** engine

· 52CE 我爱测

Random\Engine\Xoshiro256StarStar::__construct — Constructs a new xoshiro256** engine

Random\Engine\Xoshiro256StarStar::__construct

(PHP 8 >= 8.2.0)

Random\Engine\Xoshiro256StarStar::__construct — Constructs a new xoshiro256** engine

Description

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

Parameters

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 Description
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.

Errors/Exceptions

Examples

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";
?>

The above example will output:

6e013453678388c2

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。