Ejemplo n.º 1
0
<?php

include 'phprandom.php';
$img = imageCreateTrueColor(256, 256);
$colors = array();
for ($i = 0; $i < 256; $i++) {
    $colors[$i] = imageColorAllocate($img, $i, $i, $i);
}
for ($i = 0; $i < 256; $i++) {
    $random = PHPRandom::getBinary(256);
    for ($j = 0; $j < 256; $j++) {
        $value = ord(substr($random, $j, 1));
        imageSetPixel($img, $i, $j, $colors[$value]);
    }
}
header('Content-Type: image/png');
imagePNG($img);
imageDestroy($img);
Ejemplo n.º 2
0
 public function test_binary()
 {
     $count = 2000;
     $tolerance = 0.9;
     $buckets = array_fill(0, 256, 0);
     for ($i = 1; $i <= $count; $i++) {
         $len = mt_rand(2, 256);
         $str = PHPRandom::getBinary($len);
         $this->assertEquals($len, strlen($str));
         $buckets[ord($str[0])]++;
     }
     $distribution = 0;
     foreach ($buckets as $key => $value) {
         if ($value > $count / 256 * 0.5) {
             $distribution++;
         }
         if ($value < $count / 256 * 1.5) {
             $distribution++;
         }
     }
     $this->assertGreaterThan(256, $distribution);
 }