Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.