private function random(int $length = 32): string
    {
        try {
            if (empty($string = random_bytes($length))) {
                throw new \RuntimeException("Unable to generate random string");
            }
        } catch (\Throwable $e) {
            throw new \RuntimeException("Unable to generate random string", $e->getCode(), $e);
        }

        return substr(base64_encode($string), 0, $length);
    }
private function random(int $length = 32): string
    {
        try {
            if (empty($string = random_bytes($length))) {
                throw new \RuntimeException("Unable to generate random string");
            }
        } catch (\Throwable $e) {
            throw new \RuntimeException("Unable to generate random string", $e->getCode(), $e);
        }

        return substr(base64_encode($string), 0, $length);
    }
private function random ( int $ length = 32 ) : string { try { if ( empty ( $ string = random_bytes ( $ length ) ) ) { throw new \ RuntimeException ( "Unable to generate random string" ) ; } } catch ( \ Throwable $ e ) { throw new \ RuntimeException ( "Unable to generate random string" , $ e -> getCode ( ) , $ e ) ; } return substr ( base64_encode ( $ string ) , 0 , $ length ) ; }
Create a random string with desired length.

@param int $length String length. 32 symbols by default.
@return string
Create a random string with desired length .