public static function getRandomString(
        $intLength,
        $strCharacterSet = self::LETTERS_NUMBERS
    ) {
        // Cast in case there were something else
        $intLength = Type::cast($intLength, Type::INTEGER);
        $strCharacterSet = Type::cast($strCharacterSet, Type::STRING);

        if ($intLength < 1) {
            throw new Caller('Cannot generate a random string of zero length');
        }

        if (strlen(trim($strCharacterSet)) == 0) {
            throw new Caller('Character set must contain at least 1 printable character.');
        }

        return substr(
            str_shuffle(
                str_repeat($strCharacterSet, ceil($intLength / strlen($strCharacterSet)))
            ), 0, $intLength);
    }
public static function getRandomString(
        $intLength,
        $strCharacterSet = self::LETTERS_NUMBERS
    ) {
        // Cast in case there were something else
        $intLength = Type::cast($intLength, Type::INTEGER);
        $strCharacterSet = Type::cast($strCharacterSet, Type::STRING);

        if ($intLength < 1) {
            throw new Caller('Cannot generate a random string of zero length');
        }

        if (strlen(trim($strCharacterSet)) == 0) {
            throw new Caller('Character set must contain at least 1 printable character.');
        }

        return substr(
            str_shuffle(
                str_repeat($strCharacterSet, ceil($intLength / strlen($strCharacterSet)))
            ), 0, $intLength);
    }
public static function getRandomString ( $ intLength , $ strCharacterSet = self :: LETTERS_NUMBERS ) { // Cast in case there were something else $ intLength = Type :: cast ( $ intLength , Type :: INTEGER ) ; $ strCharacterSet = Type :: cast ( $ strCharacterSet , Type :: STRING ) ; if ( $ intLength < 1 ) { throw new Caller ( 'Cannot generate a random string of zero length' ) ; } if ( strlen ( trim ( $ strCharacterSet ) ) == 0 ) { throw new Caller ( 'Character set must contain at least 1 printable character.' ) ; } return substr ( str_shuffle ( str_repeat ( $ strCharacterSet , ceil ( $ intLength / strlen ( $ strCharacterSet ) ) ) ) , 0 , $ intLength ) ; }
Get a random string of a given length

@param int $intLength Length of the string which is to be produced
@param int|string $strCharacterSet Character Set to be used

@return string The generated Random string
@throws Caller
Get a random string of a given length