Skip to content

Instantly share code, notes, and snippets.

@mansueli
Created August 1, 2014 19:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mansueli/0a4b5ad01e833ff42602 to your computer and use it in GitHub Desktop.
Gist php rand() vs mt_rand()
<?php
header("Content-type: image/png");
mt_srand((double)microtime()*1000000);
$im = imagecreatetruecolor(300, 300) or die("A biblioteca GD provavelmente nao esta' instalada");
$emBranco = imagecolorallocate($im, 255, 255, 255);
for ($y = 0; $y < 300; $y++) {
for ($x = 0; $x < 300; $x++) {
if (mt_rand(0, 1)) {
imagesetpixel($im, $x, $y, $emBranco);
}
}
}
imagepng($im);
imagedestroy($im);
?>
<?php
header("Content-type: image/png");
srand((double)microtime()*1000000);
$im = imagecreatetruecolor(300, 300) or die("A biblioteca GD provavelmente nao esta' instalada");
$emBranco = imagecolorallocate($im, 255, 255, 255);
for ($y = 0; $y < 300; $y++) {
for ($x = 0; $x < 300; $x++) {
if (rand(0, 1)) {
imagesetpixel($im, $x, $y, $emBranco);
}
}
}
imagepng($im);
imagedestroy($im);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment