06-08-2008, 02:46 AM
|
#2 (permalink)
|
|
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
|
Just off the top of my head if I wanted a quick random number, I'd probably just use
PHP Code:
echo $szString = str_shuffle(time()); // or for a little more random echo $szString = str_shuffle(mktime(0, 0, 0, mt_rand(1, 12), mt_rand(1, 30), mt_rand(1980, 2010)));
...but the function I use for random strings looks more like this:
PHP Code:
static function generateRandStr ($intLength, $intEncode=0) {
// Initialize the string $szRand = (string) "";
// Generate a fairly random string for ($i = 0; $i < $intLength; $i++) { $intRand = mt_rand(0,62);
// 0 thru 9 if ($intRand < 10) { $szRand .= chr($intRand+48);
// A thru Z } else if( $intRand < 36) { $szRand .= chr($intRand+55);
// a thru z } else { $szRand .= chr($intRand+61); }
} // Determine if the string should be hashed if ($intEncode == 1) return md5($szRand); if ($intEncode == 2) return sha1($szRand); return $szRand;
}
|
|
|
|