コード例 #1
0
ファイル: memtest.php プロジェクト: riimu/kit-securerandom
<?php

require __DIR__ . '/../src/autoload.php';
$rng = new \Riimu\Kit\SecureRandom\SecureRandom();
$timer = microtime(true);
$rng->shuffle(range(0, 100000));
//$rng->getSequence(range(0, 100000), 100000);
echo 'Time: ' . round(microtime(true) - $timer, 2) . ' s' . PHP_EOL;
echo 'Memory: ' . round(memory_get_peak_usage(true) / 1024, 2) . ' kb' . PHP_EOL;
コード例 #2
0
<?php

require __DIR__ . '/../src/autoload.php';
$rng = new \Riimu\Kit\SecureRandom\SecureRandom();
/**
 * Credits for the distribution image goes to:
 * http://boallen.com/random-numbers.html
 */
header("Content-type: image/png");
$im = imagecreatetruecolor(512, 512);
$white = imagecolorallocate($im, 255, 255, 255);
$width = 512;
$height = 512;
for ($y = 0; $y < $height; $y++) {
    for ($x = 0; $x < $width; $x++) {
        //imagesetpixel($im, $rng->getInteger(0, $width - 1), $rng->getInteger(0, $height - 1), $white);
        if ($rng->getInteger(0, 1)) {
            imagesetpixel($im, $x, $y, $white);
        }
    }
}
imagepng($im);
imagedestroy($im);
コード例 #3
0
<?php

require __DIR__ . '/../src/autoload.php';
// Creates SecureRandom with a blocking reader
$rng = new \Riimu\Kit\SecureRandom\SecureRandom(new \Riimu\Kit\SecureRandom\Generator\Mcrypt(false));
var_dump($rng->getFloat());
コード例 #4
0
ファイル: types.php プロジェクト: riimu/kit-securerandom
<?php

require __DIR__ . '/../src/autoload.php';
$rng = new \Riimu\Kit\SecureRandom\SecureRandom();
var_dump(base64_encode($rng->getBytes(32)));
// Returns a random byte string
var_dump($rng->getInteger(100, 1000));
// Returns a random integer between 100 and 1000
var_dump($rng->getFloat());
// Returns a random float between 0 and 1
var_dump($rng->getArray(range(0, 100), 5));
// Returns 5 randomly selected elements from the array
var_dump($rng->choose(range(0, 100)));
// Returns one randomly chosen value from the array
var_dump($rng->shuffle(range(0, 9)));
// Returns the array in random order
var_dump($rng->getSequence('01', 32));
// Returns a random sequence of 0s and 1s with length of 32
var_dump($rng->getSequence(['a', 'b', 'c'], 5));
// Returns an array with 5 elements randomly chosen from 'a', 'b', and 'c'