note 99948 added to function.rand
| From: | eren at kesdi dot com | Date: | Thu, 16 Sep 2010 11:31:18 +0000 |
| Subject: | note 99948 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-172632@lists.php.net to get a copy of this message | ||
Generate Random hexadecimal number
<?php
// http://blog.kesdi.com
function randhex($minbasamak,$maxbasamak)
{
$a=0;
$b=0;
$hexmin="";
$hexmax="";
while ($a<$minbasamak)
{
$hexmin=$hexmin."0";
$a++;
}
while ($b<$maxbasamak)
{
$hexmax=$hexmax."F";
$b++;
}
$min = hexdec($hexmin); // minimum hexadec converting
$max = hexdec($hexmax); // maximum hexadec converting
$random = mt_rand($min, $max); // create random value
$random_hex = dechex($random); // converting hexadecimal
if (strlen($random_hex) > $maxbasamak OR strlen($random_hex) < $minbasamak)
randhex($minbasamak,$maxbasamak); // repeate
else
return $random_hex;
}
// sample
echo randhex(2,4);
?>
----
Server IP: 160.75.100.7
Probable Submitter: 88.252.28.11
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/99948
Del: integrated -- https://master.php.net/note/delete/99948/integrated
Del: useless -- https://master.php.net/note/delete/99948/useless
Del: bad code -- https://master.php.net/note/delete/99948/bad+code
Del: spam -- https://master.php.net/note/delete/99948/spam
Del: non-english -- https://master.php.net/note/delete/99948/non-english
Del: in docs -- https://master.php.net/note/delete/99948/in+docs
Del: other reasons-- https://master.php.net/note/delete/99948
Reject -- https://master.php.net/note/reject/99948
Search -- https://master.php.net/manage/user-notes.php