public static function random($length = 10, $isReadable = true): string
    {
        $result = '';

        if ($isReadable) {
            $vowels = ['a', 'e', 'i', 'o', 'u', '0'];
            $consonants = [
                'b',
                'c',
                'd',
                'f',
                'g',
                'h',
                'j',
                'k',
                'l',
                'm',
                'n',
                'p',
                'r',
                's',
                't',
                'v',
                'w',
                'x',
                'y',
                'z',
                '1',
                '2',
                '3',
                '4',
                '5',
                '6',
                '7',
                '8',
                '9',
            ];

            $max = $length / 2;

            for ($pos = 1; $pos <= $max; $pos++) {
                $result .= $consonants[random_int(0, count($consonants) - 1)];
                $result .= $vowels[random_int(0, count($vowels) - 1)];
            }
        } else {
            $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

            for ($pos = 0; $pos < $length; $pos++) {
                $result .= $chars[mt_rand() % strlen($chars)];
            }
        }

        return $result;
    }
public static function random($length = 10, $isReadable = true): string
    {
        $result = '';

        if ($isReadable) {
            $vowels = ['a', 'e', 'i', 'o', 'u', '0'];
            $consonants = [
                'b',
                'c',
                'd',
                'f',
                'g',
                'h',
                'j',
                'k',
                'l',
                'm',
                'n',
                'p',
                'r',
                's',
                't',
                'v',
                'w',
                'x',
                'y',
                'z',
                '1',
                '2',
                '3',
                '4',
                '5',
                '6',
                '7',
                '8',
                '9',
            ];

            $max = $length / 2;

            for ($pos = 1; $pos <= $max; $pos++) {
                $result .= $consonants[random_int(0, count($consonants) - 1)];
                $result .= $vowels[random_int(0, count($vowels) - 1)];
            }
        } else {
            $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

            for ($pos = 0; $pos < $length; $pos++) {
                $result .= $chars[mt_rand() % strlen($chars)];
            }
        }

        return $result;
    }
public static function random ( $ length = 10 , $ isReadable = true ) : string { $ result = '' ; if ( $ isReadable ) { $ vowels = [ 'a' , 'e' , 'i' , 'o' , 'u' , '0' ] ; $ consonants = [ 'b' , 'c' , 'd' , 'f' , 'g' , 'h' , 'j' , 'k' , 'l' , 'm' , 'n' , 'p' , 'r' , 's' , 't' , 'v' , 'w' , 'x' , 'y' , 'z' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , ] ; $ max = $ length / 2 ; for ( $ pos = 1 ; $ pos <= $ max ; $ pos ++ ) { $ result .= $ consonants [ random_int ( 0 , count ( $ consonants ) - 1 ) ] ; $ result .= $ vowels [ random_int ( 0 , count ( $ vowels ) - 1 ) ] ; } } else { $ chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ; for ( $ pos = 0 ; $ pos < $ length ; $ pos ++ ) { $ result .= $ chars [ mt_rand ( ) % strlen ( $ chars ) ] ; } } return $ result ; }
Generate readable random string

@param int  $length
@param bool $isReadable
@return string
Generate readable random string