src/Viserio/Component/Support/Str.php
public static function random(int $length = 64, string $characters = CharacterType::PRINTABLE_ASCII): string
    {
        $str = '';
        $l   = self::length($characters) - 1;

        for ($i = 0; $i < $length; $i++) {
            $r = \random_int(0, $l);
            $str .= $characters[$r];
        }

        return $str;
    }
public static function random(int $length = 64, string $characters = CharacterType::PRINTABLE_ASCII): string
    {
        $str = '';
        $l   = self::length($characters) - 1;

        for ($i = 0; $i < $length; $i++) {
            $r = \random_int(0, $l);
            $str .= $characters[$r];
        }

        return $str;
    }
Generate a random string of a given length and character set.

@param int    $length     How many characters do you want?
@param string $characters Which characters to choose from

@return string