PHP code example of duzun / p2peg

1. Go to this page and download the library: Download duzun/p2peg library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

duzun / p2peg example snippets




$P2PEG = P2PEG::instance();

$str = $P2PEG->str($length);

$int1 = $P2PEG->int();
$int2 = $P2PEG->int16();
$int3 = $P2PEG->int32();
$int4 = $P2PEG->rand($min, $max, $algo="int"); // see PHP's rand() in docs

$text = $P2PEG->text($length);

$text = $P2PEG->alpha('a-z0-9AUOIE!', $length);
// or
$text = $P2PEG->text($length, 'a-z0-9AUOIE!');

$hex = $P2PEG->hex($length);

$rand_int = $P2PEG->rand32($strict=true);

$rand_long = $P2PEG->rand64();

// x32
$P2PEG->xorShift32($strict=true);
$P2PEG->xorShift128($strict=true);
$P2PEG->xorwow($strict=true); // default in Nvidia's CUDA toolkit

// x64
$P2PEG->xorShift1024Star();
$P2PEG->xorShift128Plus();
$P2PEG->splitMix64();

$P2PEG->state_file = "/path/to/data/p2peg.dat";

$P2PEG->setSecret("some uniq secret that no one knows");

$P2PEG->seed("some (random) string");

mt_srand(crc32($P2PEG->seed()));
// or
mt_srand($P2PEG->int32());

$P2PEG->seedRandomDev("some (optional) entropy");

$int64 = $P2PEG->int(7);

$P2PEG->servImg($width,$height,$method='rand32',$itemSize=0);

$allowMethods = array(
    // P2PEG entropy
    'int', 'int32', 'int16', 'str', 'seed', 'text', 'hex', 
    // PRNGs seeded by P2PEG
    'rand32', 'xorShift32', 'xorShift128', 'xorwow', 
    'rand64', 'xorShift128Plus', 'xorShift1024Star', 'splitMix64', 
    // raw data
    'dynEntropy','clientEntropy','networkEntropy',
);

$P2PEG->networkEntropy($autoseed=true);

$P2PEG->expensiveEntropy($autoseed=true);