array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'uk', ), 'this' => array ( 0 => 'random-engine-pcgoneseq128xslrr64.jump.php', 1 => 'Random\\Engine\\PcgOneseq128XslRr64::jump', 2 => 'Efficiently move the engine ahead multiple steps', ), 'up' => array ( 0 => 'class.random-engine-pcgoneseq128xslrr64.php', 1 => 'Random\\Engine\\PcgOneseq128XslRr64', ), 'prev' => array ( 0 => 'random-engine-pcgoneseq128xslrr64.generate.php', 1 => 'Random\\Engine\\PcgOneseq128XslRr64::generate', ), 'next' => array ( 0 => 'random-engine-pcgoneseq128xslrr64.serialize.php', 1 => 'Random\\Engine\\PcgOneseq128XslRr64::__serialize', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/random/random/engine/pcgoneseq128xslrr64/jump.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

Random\Engine\PcgOneseq128XslRr64::jump

(PHP 8 >= 8.2.0)

Random\Engine\PcgOneseq128XslRr64::jumpEfficiently move the engine ahead multiple steps

Опис

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

Значення, що повертаються

Не повертає значень.

Помилки/виключення

Приклади

Приклад #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