支持随机生成只包含数字的随机字符串长度为1-8
@param int $length
@return int
432748
public static function randNumbers($length = 6)
    {
        if ($length < 0) $length = 1;
        if ($length > 8) $length = 8;
        $start = pow(10, $length - 1);
        return mt_rand($start, ($start * 10) - 1);
    }
44373
public function randomString($length = 32)
        {
            $string     = "";
            $possible   = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`~!@#$%^&*()-_+=";

            for ($i = 0; $i < $length; $i++) {
                $char = $possible[mt_rand(0, strlen($possible)-1)];
                $string .= $char;
            }

            return $string;
        }
861888
public function maxLength(int $length) : Element
    {
        $this->attributes['maxlength'] = (int)$length;
        return $this->addTest('maxlength', function($value) use ($length) {
            return mb_strlen(trim($value), 'UTF-8') <= (int)$length;
        });
    }
5996
public static function generate_pin($length = 8)
    {
        $factory = new \RandomLib\Factory;
        $generator = $factory->getLowStrengthGenerator();
        #--with easy to speak letters
        #$alfabet = range('A', 'Z');
        #$consonants = array_diff($alfabet, array('Y', 'H', 'W', 'Q', 'C')) ;
        #$chars = implode('',$consonants);
        #--full
        #$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-#';
        #--only numbers
        $chars = '0123456789';
        $randomString = $generator->generateString($length, $chars);
        return $randomString;
    }
919915
protected function keygen($length)
    {
        $key = '';
        for($i = 1; $i < $length; $i++) {
            $key .= mt_rand(0,9);
        }
        $key .= mt_rand(1,9);
        
        return $key;
    }
360813
public static function generator( $length = 32 ) {
		$out = Hash::base64( Route::HTTP_HOST() . random_bytes( $length ), 1 );

		return $out;
	}
267356
protected static function generateRandomString($length)
    {
        $characters = static::CHARACTERS;

        $charactersLength = strlen($characters);
        $randomString = '';
        for ($i = 0; $i < $length; $i++) {
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }

        return $randomString;
    }
1078518
static function getRandomString($length = 8)
    {

        $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

        $value = '';
        $charsLength = strlen($chars) - 1;

        for ($i = 1 ; $i <= $length; $i++) {
            $value .= $chars[rand(0, $charsLength)];
        }

        return $value;

    }
12331
public static function genRandomChar($length = 8)
    {
        // 密码字符集，可任意添加你需要的字符
        //$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        $chars = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
        $char = '';
        for ($i = 0; $i < $length; $i++) {
            $char .= $chars[mt_rand(0, strlen($chars) - 1)];
        }
        return $char;
    }
1148518
protected function generate($length = null)
    {
        $generator = new RandomGenerator();
        $result = $generator->randomToken('sha256');
        if ($length !== null) {
            return substr($result, 0, $length);
        }
        return $result;
    }
143195
public static function randomLatinNumeric(int $length): string
    {
        $ret = 97;
        $out = null;
        for ($i = 0; $i < $length; $i++) {
            $offset = mt_rand(0, 15);
            $char = chr($ret + $offset);
            $posibility = mt_rand(0, 2);
            if ($posibility == 0) {
                // 33% - add random numeric
                $out .= mt_rand(0, 9);
            } elseif ($posibility == 1) {
                // 33% - make upper offset+ret
                $out .= strtoupper($char);
            } else {
                $out .= $char;
            }
        }
        return $out;
    }
987168
public static function random($length) {
    if ($length <= 0) return '';
    $str = '';
    for ($i = 0; $i < $length; $i++) {
      $rand = rand(0, 35);
      if ($rand >= 10)
        $str .= chr(ord('a') + $rand-10); // a - z
      else
        $str .= chr(ord('0') + $rand);    // 0 - 9
    }
    
    return $str;
  }
249311
public static function randomNumberUsingRandomInt($prefix = '4', $length = 8)
    {
        $max = (int)str_pad("9", $length - strlen($prefix), "9");
        return $prefix . (string)str_pad(random_int(0, $max), $length - strlen($prefix), "0", STR_PAD_LEFT);
    }
1017997
public static function getRandomString(int $length = 64) : string
    {
        $characters = "01234567890123456789";
        $characters .= "abcdefghijklmnopqrstuvwxyz";

        $string_generated = "";

        while ($length--) {
            $string_generated .= $characters[mt_rand(0, 45)];
        }

        return $string_generated;
    }
918178
public static function random($length = 16)
    {
        $string = '';

        while (($len = strlen($string)) < $length) {
            $size = $length - $len;

            $bytes = static::randomBytes($size);

            $string .= substr(str_replace(array('/', '+', '='), '', base64_encode($bytes)), 0, $size);
        }

        return $string;
    }
233692
function recv($length)
    {
        $content = '';
        $readn = $length;

        while ($readn > 0)
        {
            if ($readn > 8192)
            {
                $tmp = fread($this->fp, 8192);
            }
            else
            {
                $tmp = fread($this->fp, $readn);
            }
            if (empty($tmp))
            {
                break;
            }
            $content .= $tmp;
            $readn -= strlen($tmp);
        }
        return $content;
    }
679625
protected function _bufferSize($length)
    {
        if ($this->_limit !== null) {
            $position = $this->tell();
            $max = $this->_start + $this->_limit;
            $length = $max - $position;
        }
        if ($length === null) {
            $length = $this->_bufferSize;
        }
        return $length;
    }