note 70952 added to function.mt-rand
| From: | David at osu1 dot php dot net | Date: | Mon, 06 Nov 2006 08:40:37 +0000 |
| Subject: | note 70952 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119418@lists.php.net to get a copy of this message | ||
Shouldn't it be a greater than (>) sign rather than a not equal (!=) sign? Because
you're just checking to see if it is exactly six. So if it is 7 it, won't try to fix it.
So wouldn't this be better?
<?
//....
if (strlen($random_hex) < "6") // sometimes it returns an only 5, or less, char
Hex-Code,
hexcode(); // so the function has to be repeat
elseif (strlen($random_hex) > "6") // sometimes it returns 7 or more characters
//...I don't know how to make it do only six, but your code seems to only check to make sure it
doesn't do less than 6; nothing to counter doing more than 6.... so here would be some code to
reduce the size back to 6 if it went over.
else
echo $random_hex; // returns the Hex-Code
}
//...
?>
----
Server IP: 66.163.161.117
Probable Submitter: 59.6.217.121
----
Manual Page -- http://www.php.net/manual/en/function.mt-rand.php
Edit -- https://master.php.net/note/edit/70952
Del: integrated -- https://master.php.net/note/delete/70952/integrated
Del: useless -- https://master.php.net/note/delete/70952/useless
Del: bad code -- https://master.php.net/note/delete/70952/bad+code
Del: spam -- https://master.php.net/note/delete/70952/spam
Del: non-english -- https://master.php.net/note/delete/70952/non-english
Del: in docs -- https://master.php.net/note/delete/70952/in+docs
Del: other reasons-- https://master.php.net/note/delete/70952
Reject -- https://master.php.net/note/reject/70952
Search -- https://master.php.net/manage/user-notes.php