View Single Post
Old 06-08-2008, 02:46 AM   #2 (permalink)
delayedinsanity
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

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(000mt_rand(112), mt_rand(130), mt_rand(19802010))); 
...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;


delayedinsanity is offline  
Reply With Quote