Generate a code

@access private
@param int $len  The code length
@return string
553465
function generateCode($len)
  {
    $code = '';

    for($i = 1, $cslen = strlen($this->charset); $i <= $len; ++$i) {
      $code .= strtoupper( $this->charset{rand(0, $cslen - 1)} );
    }
    return $code;
  }
830273
public static function generateSalt(
        $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
        $saltLength = 30
    ){
        return substr(str_shuffle(str_repeat((string) $chars,10)),0, (int) $saltLength);
    }
688923
public function read($len = null)
    {
        if ($this->processed === true) {
            return -1; // EOF
        }

        // Read XML
        $php = null;
        while (($buffer = $this->in->read($len)) !== -1) {
            $php .= $buffer;
        }

        if ($php === null) { // EOF?

            return -1;
        }

        if (empty($php)) {
            $this->log("PHP file is empty!", Project::MSG_WARN);

            return ''; // return empty string, don't attempt to strip whitespace
        }

        // write buffer to a temporary file, since php_strip_whitespace() needs a filename
        $file = new PhingFile(tempnam(PhingFile::getTempDir(), 'stripwhitespace'));
        file_put_contents($file->getAbsolutePath(), $php);
        $output = php_strip_whitespace($file->getAbsolutePath());
        unlink($file->getAbsolutePath());

        $this->processed = true;

        return $output;
    }
223879
public function read($len)
    {
        // happy path to return empty string for zero length string
        if ($len === 0) {
            return '';
        }

        // happy path for single byte strings without using substrings
        if ($len === 1 && isset($this->buffer[$this->bufferPos])) {
            return $this->buffer[$this->bufferPos++];
        }

        // ensure buffer size contains $len bytes by checking target buffer position
        if ($len < 0 || !isset($this->buffer[$this->bufferPos + $len - 1])) {
            throw new \LogicException('Not enough data in buffer to read ' . $len . ' bytes');
        }
        $buffer = \substr($this->buffer, $this->bufferPos, $len);
        $this->bufferPos += $len;

        return $buffer;
    }
1051406
public function setBodySignedLen($len)
    {
        if (true === $len) {
            $this->showLen = true;
            $this->maxLen = PHP_INT_MAX;
        } elseif (false === $len) {
            $this->showLen = false;
            $this->maxLen = PHP_INT_MAX;
        } else {
            $this->showLen = true;
            $this->maxLen = (int) $len;
        }

        return $this;
    }
771884
public static function randStr($len = 6, $format = 'ALL')
    {
        switch (strtoupper($format)) {
            case 'ALL':
                $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';
                break;
            case 'CHAR':
                $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-@#~';
                break;
            case 'NUMBER':
                $chars = '0123456789';
                break;
            default :
                $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-@#~';
                break;
        }
        mt_srand((double)microtime() * 1000000 * getmypid());
        $randStr = "";
        while (strlen($randStr) < $len)
            $randStr .= substr($chars, (mt_rand() % strlen($chars)), 1);
        return $randStr;
    }
1353111
public function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->_initialize();
            $this->setInitialized(true);
        }

        $buffer = $this->in->read($len);

        if ($buffer === -1) {
            return -1;
        }

        $lines = explode("\n", $buffer);
        $filtered = [];

        foreach ($lines as $line) {
            $line = $this->_prefix . $line;
            $filtered[] = $line;
        }

        $filtered_buffer = implode("\n", $filtered);

        return $filtered_buffer;
    }
685427
public function read($len = null)
    {
        if (!$this->getInitialized()) {
            $this->_initialize();
            $this->setInitialized(true);
        }

        $buffer = $this->in->read($len);

        if ($buffer === -1) {
            return -1;
        }

        $lines = explode("\n", $buffer);
        $matched = [];

        $regexpsSize = count($this->_regexps);
        foreach ($lines as $line) {
            for ($i = 0; $i < $regexpsSize; $i++) {
                $regexp = $this->_regexps[$i];
                $re = $regexp->getRegexp($this->getProject());
                $re->setIgnoreCase(!$this->casesensitive);
                $matches = $re->matches($line);
                if (!$matches) {
                    $line = null;
                    break;
                }
            }
            if ($line !== null) {
                $matched[] = $line;
            }
        }
        $filtered_buffer = implode("\n", $matched);

        if ($this->isNegated()) {
            $filtered_buffer = implode("\n", array_diff($lines, $matched));
        }

        return $filtered_buffer;
    }
1025844
public function getSalt($len)
    {
        $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()-=_+';
        $l = strlen($chars) - 1;
        $str = '';
        for ($i = 0; $i < $len; ++$i) {
            $str .= $chars[mt_rand(0, $l)];
        }
        return $str;
    }
690505
public function generate($size)
    {
        $result = '';
        while (Util::safeStrlen($result) < $size) {
            $result = uniqid($result, true);
        }

        return Util::safeSubstr($result, 0, $size);
    }
360515
public function length($len, $msg)
    {
        if(strlen(trim($this->_value)) != $len) {
            $this->_errors[] = $msg;
        }
        return $this;
    }
1010447
public static function genRandomStr($l) {
		$p = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
		$s = '';
		for ($i = 0; $i < $l; $i++) {
			$s .= $p[mt_rand(0, (mb_strlen($p) - 1))];
		}
		return $s;
	}
573899
function strtrunc($charset, $string, $len) {
		if ($len <= 0) {
			return '';
		}

		if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['t3lib_cs_utils'] == 'mbstring') {
			return mb_strcut($string, 0, $len, $charset);
		} elseif ($charset == 'utf-8') {
			return $this->utf8_strtrunc($string, $len);
		} elseif ($this->eucBasedSets[$charset]) {
			return $this->euc_strtrunc($string, $len, $charset);
		} elseif ($this->twoByteSets[$charset]) {
			if ($len % 2) {
				$len--;
			} // don't cut at odd positions
		} elseif ($this->fourByteSets[$charset]) {
			$x = $len % 4;
			$len -= $x; // realign to position dividable by four
		}
			// treat everything else as single-byte encoding
		return substr($string, 0, $len);
	}
138497
protected function makeDefinition($type, $len = 0, $name = null)
    {
        $lpad     = str_repeat($this->indentWith, $this->depth);
        $namePart = '';

        if (!is_null($name) && $name !== '') {
            $namePart = "[<span style='color:#090;'>$name</span>] ";
        }

        return "{$lpad}{$namePart}<span style='color:#00a;'>{$type}</span> ({$len})";
    }
974151
public function read($len = null)
    {
        $buffer = $this->in->read($len);
        if ($buffer === -1) {
            return -1;
        }
        $newStr = '';
        $tokens = token_get_all($buffer);

        foreach ($tokens as $token) {
            if (is_array($token)) {
                list($id, $text) = $token;

                switch ($id) {
                    case T_COMMENT:
                    case T_DOC_COMMENT:
                        // no action on comments
                        continue 2;

                    default:
                        $newStr .= $text;
                        continue 2;
                }
            }
            $newStr .= $token;
        }

        return $newStr;
    }
1346506
protected static function generateSalt(): string
    {
        $result = '';

        static::validateSaltMinLength();

        $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $poolSize = strlen($pool);
        for ($i = 0; $i < static::$saltMinLength; $i++) {
            $result .= $pool[rand(0, $poolSize - 1)];
        }

        return $result;
    }
958649
protected static function makeBin($str, $len)
    {
        if ($str instanceof self) {
            return $str->bytes;
        }
        if (\strlen($str) === $len) {
            return $str;
        }

        $str = (string)preg_replace([
            // strip URN scheme and namespace
            '/^urn:uuid:/is',
            // strip non-hex characters
            '/[^a-f0-9]/is',
        ], '', $str);

        if (\strlen($str) !== ($len * 2)) {
            return null;
        }

        return pack('H*', $str);
    }