note 69917 added to function.mt-rand

From: Date: Tue, 26 Sep 2006 14:00:16 +0000
Subject: note 69917 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-117682@lists.php.net to get a copy of this message
<?php // Generates a max."6 char" Hex-Code function hexcode() { $min = hexdec("000000"); // result is 0 and sets the min-value for mt_rand $max = hexdec("FFFFFF"); // result is 16777215 and sets the max-value for mt_rand $random = mt_rand($min, $max); // creates a radom number between 0 and 16777215 $random_hex = dechex($random); // transforms the random number into a Hex-Code // now the test, if the result has 6 chars if (strlen($random_hex) != "6") // sometimes it returns an only 5, or less, char Hex-Code, hexcode(); // so the function has to be repeat else echo $random_hex; // returns the Hex-Code } hexcode(); ?> ---- Server IP: 217.160.72.57 Probable Submitter: 213.23.14.170 ---- Manual Page -- http://www.php.net/manual/en/function.mt-rand.php Edit -- https://master.php.net/note/edit/69917 Del: integrated -- https://master.php.net/note/delete/69917/integrated Del: useless -- https://master.php.net/note/delete/69917/useless Del: bad code -- https://master.php.net/note/delete/69917/bad+code Del: spam -- https://master.php.net/note/delete/69917/spam Del: non-english -- https://master.php.net/note/delete/69917/non-english Del: in docs -- https://master.php.net/note/delete/69917/in+docs Del: other reasons-- https://master.php.net/note/delete/69917 Reject -- https://master.php.net/note/reject/69917 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117682) next »