Results of 1 - 1 of about 1 for LinearCongruentialGenerator (0.002 sec.)
- Random\Engine::generate — ランダムな値を生成する | PHP 8.3 9414
- Random\Engine::generate (PHP 8 >= 8.2.0) Random\Engine::generate — ランダムな値を生成する 説明 public function Random\Engine::generate (): string ランダムな値を生成し、アルゴリズムの内部的なステートをひとつ進めます。 ランダムな値は、ランダム
... が必要な時に、 無限ループに陥ることを避けるためです。 例 例1 Random\Engine::generate() の例 <?php /** * 65536 を法とする LCG(Linear Congruential Generator, 線形合同法)を実装し、 * 61 を掛けて 17 を足し、8ビットの整数を返します。 * * 注意: このエンジンはデモの用途のみに適した ... ここで示す実装は、16ビットというとても短い周期しか持っていません。 * これは、殆どの現実の需要を満たしません。 */ final class LinearCongruentialGenerator implements \Random\Engine { private int $state ; public function __construct (? int $seed = null ) { if ( $seed === null ) ... = ( 61 * $this -> state + 17 ) & 0xffff ; return pack ( 'C' , $this -> state >> 8 ); } } $r = new \Random\Randomizer ( new LinearCongruentialGenerator ( seed : 1 ) ); echo "Lucky Number: " , $r -> getInt ( 0 , 99 ), "\n" ; ?> 上の例の出力は以下となります。 Lucky Number: 4 ...
-
https://man.mtool.work/php/8.3/random-engine.generate.html
PREV
1
NEXT