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

Random\Engine\PcgOneseq128XslRr64::jump · Efficiently move the engine ahead multiple steps

· 52CE 我爱测

Random\Engine\PcgOneseq128XslRr64::jump — Efficiently move the engine ahead multiple steps

Random\Engine\PcgOneseq128XslRr64::jump

(PHP 8 >= 8.2.0)

Random\Engine\PcgOneseq128XslRr64::jump — Efficiently move the engine ahead multiple steps

说明

public function Random\Engine\PcgOneseq128XslRr64::jump(int $advance): void

Moves the algorithm’s state ahead by the number of steps given by advance, as if Random\Engine\PcgOneseq128XslRr64::generate() was called that many times.

参数

advance

The number of steps to move ahead; must be 0 or greater.

返回值

没有返回值。

错误/异常

  • If advance is less than 0, a ValueError will be thrown.

示例

示例 #1 Random\Engine\PcgOneseq128XslRr64::jump() example

<?php
$a = new \Random\Engine\PcgOneseq128XslRr64(0);
$b = clone $a;

for ($i = 0; $i < 1_000; $i++) {
    $a->generate();
}
$b->jump(1_000);

echo "A: ", bin2hex($a->generate()), "\n";
echo "B: ", bin2hex($b->generate()), "\n";
?>

以上示例会输出:

A: e6d0d5813913a424
B: e6d0d5813913a424

示例 #2 Randomizer methods may call the engine more than once

<?php
$a = new \Random\Randomizer(new \Random\Engine\PcgOneseq128XslRr64(42659));
$b = new \Random\Randomizer(clone $a->engine);

$a->getInt(1, 1572864); // Performs two calls to generate().
$a->getInt(1, 1572864);

$b->engine->jump(2);

// Because the first call to ->getInt() called ->generate() twice
// the engines do not match up after performing a ->jump(2).
echo "A: ", bin2hex($a->engine->generate()), "\n";
echo "B: ", bin2hex($b->engine->generate()), "\n";

// Now the B engine matches the A engine.
echo "B: ", bin2hex($b->engine->generate()), "\n";
?>

以上示例会输出:

A: 1e9f3107d56653d0
B: a156c0086dd79d44
B: 1e9f3107d56653d0

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

资料来源与适用范围

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

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

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