public static function get_randomString($length = 12, $type = 'pAan', $additional = '')
    {
        $sources = array(
            'p' => '!#$%&()=?*+-_:.;,<>',        // Punctuation
            'a' => 'abcdefghijklmnopqrstuvwxyz', // alpha
            'A' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', // Alpha
            'n' => '1234567890'                  // Numeric
        );
        
        $source = '';

        foreach ( $sources as $k => $s ) {
            if (strstr($type, $k)) {
                $source .= $s;
            }
        }

        $source .= $additional;

        if ($source == '') {
            throw new Exception('Type Error in get_randomString', 1);
        }
        
        srand((double)microtime()*1000000);
        $i = 0; $r = '';
        while ($i < $length) {
            $num = rand() % strlen($source);
            $tmp = substr($source, $num, 1);
            $r = $r . $tmp;
            $i++;
        }
        return $r;
    }
public static function get_randomString($length = 12, $type = 'pAan', $additional = '')
    {
        $sources = array(
            'p' => '!#$%&()=?*+-_:.;,<>',        // Punctuation
            'a' => 'abcdefghijklmnopqrstuvwxyz', // alpha
            'A' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', // Alpha
            'n' => '1234567890'                  // Numeric
        );
        
        $source = '';

        foreach ( $sources as $k => $s ) {
            if (strstr($type, $k)) {
                $source .= $s;
            }
        }

        $source .= $additional;

        if ($source == '') {
            throw new Exception('Type Error in get_randomString', 1);
        }
        
        srand((double)microtime()*1000000);
        $i = 0; $r = '';
        while ($i < $length) {
            $num = rand() % strlen($source);
            $tmp = substr($source, $num, 1);
            $r = $r . $tmp;
            $i++;
        }
        return $r;
    }
public static function get_randomString ( $ length = 12 , $ type = 'pAan' , $ additional = '' ) { $ sources = array ( 'p' => '!#$%&()=?*+-_:.;,<>' , // Punctuation 'a' => 'abcdefghijklmnopqrstuvwxyz' , // alpha 'A' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' , // Alpha 'n' => '1234567890' // Numeric ) ; $ source = '' ; foreach ( $ sources as $ k => $ s ) { if ( strstr ( $ type , $ k ) ) { $ source .= $ s ; } } $ source .= $ additional ; if ( $ source == '' ) { throw new Exception ( 'Type Error in get_randomString' , 1 ) ; } srand ( ( double ) microtime ( ) * 1000000 ) ; $ i = 0 ; $ r = '' ; while ( $ i < $ length ) { $ num = rand ( ) % strlen ( $ source ) ; $ tmp = substr ( $ source , $ num , 1 ) ; $ r = $ r . $ tmp ; $ i ++ ; } return $ r ; }
Generates a passwordish random string

@access public
@param  integer $length the length of the string
@param  string  $type   keys of chartypes to be used. See beginning of declaration.
@param  string  $additional optional string containing additional chars to use beside the ones in $type

@return string
Generates a passwordish random string