public function generate()
    {
        $chars = $this->validChars();
        $numChars = strlen($chars) - 1;
        $length = $this->getLength();
        $code = array();
        for ($i = 0; $i < $length; ++$i) {
            $code[] = $chars[random_int(0, $numChars)];
        }

        return implode('', $code);
    }