note 99947 deleted from function.mt-rand by danbrown
| From: | danbrown@php.net | Date: | Thu, 16 Sep 2010 15:45:22 +0000 |
| Subject: | note 99947 deleted from function.mt-rand by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172648@lists.php.net to get a copy of this message | ||
Note Submitter: eren at kesdi dot com
----
Random hexadecimal creator
<?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); // repate
else
return $random_hex;
}
// sample
echo randhex(2,4);
?>