note 119430 added to function.mt-rand
| From: | nospamremove dot francois dot gannaz at silecs dot info | Date: | Fri, 03 Jun 2016 10:49:24 +0000 |
| Subject: | note 119430 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-205651@lists.php.net to get a copy of this message | ||
rand() comes from the libc, and mt_rand() is internal to PHP. So the differences vary with their
respective versions.
On a 64b Debian Stretch with PHP 5.6.21, there is no visible difference: http://oi64.tinypic.com/2nkqas6.jpg
This image compares the two functions. In the top half with random points, in the lower half with
random intensity on each point. This is totally different from what was obtained 4 years ago in
another note, with an unknown environment.
Here is the code for this visual comparison.
<?php
$sizex = 400;
$sizey = 400;
$img = imagecreatetruecolor(2 * $sizex, 2 * $sizey);
$white = imagecolorallocate($img, 255, 255, 255);
$inks = array_map(
function($r) use($img) { return imagecolorallocate($img, $r, $r, $r); },
range(0, 255)
);
for ($x = 0 ; $x < $sizex ; $x++) {
for ($y = 0 ; $y < $sizey ; $y++) {
// placing ($sizex x $sizey) white points at random in the top half
imagesetpixel($img, rand(0, $sizex - 1), rand(0, $sizey - 1), $white);
imagesetpixel($img, $sizex + mt_rand(0, $sizex - 1), mt_rand(0, $sizey - 1), $white);
// random intensity for each point in the lower half
imagesetpixel($img, $x, $sizey + $y, $inks[rand(0, 255)]);
imagesetpixel($img, $sizex + $x, $sizey + $y, $inks[mt_rand(0, 255)]);
}
}
header("Content-type: image/png");
imagepng($img);
?>
----
Server IP: 72.52.91.14
Probable Submitter: 88.172.133.112
----
Manual Page -- http://php.net/manual/en/function.mt-rand.php
Edit -- https://master.php.net/note/edit/119430
Del: integrated -- https://master.php.net/note/delete/119430/integrated
Del: useless -- https://master.php.net/note/delete/119430/useless
Del: bad code -- https://master.php.net/note/delete/119430/bad+code
Del: spam -- https://master.php.net/note/delete/119430/spam
Del: non-english -- https://master.php.net/note/delete/119430/non-english
Del: in docs -- https://master.php.net/note/delete/119430/in+docs
Del: other reasons-- https://master.php.net/note/delete/119430
Reject -- https://master.php.net/note/reject/119430
Search -- https://master.php.net/manage/user-notes.php