note 99948 deleted from function.rand by danbrown

From: Date: Thu, 16 Sep 2010 15:45:04 +0000
Subject: note 99948 deleted from function.rand by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172647@lists.php.net to get a copy of this message
Note Submitter: eren at kesdi dot com ---- 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); ?>

« previous php.notes (#172647) next »