generate random string of 6 digits

@param int    $len
@param string $format
@return string
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;
    }
255413
public function generateAlphaNumToken($length)
    {
        $characters = str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');

        srand((float)microtime() * 1000000);

        $token = '';

        do
        {
            shuffle($characters);
            $token .= $characters[mt_rand(0, (count($characters) - 1))];
        } while (strlen($token) < $length);

        return $token;
    }
694895
public function protectedRandomNumberHelper($size)
    {
        $crypt_random = function_exists('crypt_random_string') ||
        (! class_exists('Crypt_Random') && function_exists('crypt_random_string'));
        if ($crypt_random) {
            $random = crypt_random_string($size);
        } else {
            $random = '';
            if ($size & 1) {
                $random .= chr(mt_rand(0, 255));
            }
            $blocks = $size >> 1;
            for ($i = 0; $i < $blocks; ++ $i) {
                // mt_rand(-2147483648, 0x7FFFFFFF) always produces -2147483648 on some systems
                $random .= pack('n', mt_rand(0, 0xFFFF));
            }
        }
        return new BigInteger($random, 256);
    }
104321
static public function buildCountRand ($number,$length=4,$mode=1) {
            if($mode==1 && $length<strlen($number) ) {
                //不足以生成一定数量的不重复数字
                return false;
            }
            $rand   =  array();
            for($i=0; $i<$number; $i++) {
                $rand[] =   self::randString($length,$mode);
            }
            $unqiue = array_unique($rand);
            if(count($unqiue)==count($rand)) {
                return $rand;
            }
            $count   = count($rand)-count($unqiue);
            for($i=0; $i<$count*3; $i++) {
                $rand[] =   self::randString($length,$mode);
            }
            $rand = array_slice(array_unique ($rand),0,$number);
            return $rand;
    }
49222
static public function TRACE_ID($len = 8)
    {
        $trace_id =  substr(md5(uniqid(mt_rand(), true)), 0-$len);
        return $trace_id;
    }
870716
public static function len($text, $len)
	{
	    if (is_array($len)) {
	        if (!isset($len['len'])) {
	            throw new \InvalidArgumentException('The $len argument must have "len" key');
	        }
	        $len = $len['minLen'];
	    }

	    return strlen($text) == $len;
	}
362249
public static function randomChars( $seed, $len )
	{
		$result = '';

		for ( $i = 0; $i < $len; $i++ )
			$result .= $seed[random_int( 0, strlen( $seed ) )];

		return $result;
	}
658858
public function size($len)
    {
        $len = (int) $len;
        if (is_string($this->value)) {
            $message = ['%s {{does not have|has}} a string length of %s', $this->value, $len];
            $this->assert((strlen($this->value) === $len), $message);
        }

        if (is_int($this->value)) {
            $message = ['Integer %s {{does not have|has}} a size of %s', $this->value, $len];
            $this->assert(($this->value === $len), $message);
        }

        if (is_array($this->value)) {
            $message = ['Array {{does not have|has}} a size of %s', $len];
            $this->assert((count($this->value) === $len), $message);
        }

        return $this;
    }
731912
public static function create($lenght)
    {
        $characters = 'abcdefghijk01234lmnopq56789rstuxyvwz';
        $charLenght = strlen($characters);

        $string = '';
        for ($i = 0; $i < $lenght; $i++) {
            $index = mt_rand(0, $charLenght - 1);
            $string .= $characters[$index];
        }

        return $string;
    }
862458
public function generateRandomString($length)
    {
        do {
            $bytes = base64_encode($this->random->nextBytes($length));
            $string = substr(strtr($bytes, array('+' => '', '/' => '', '=' => '')), 0, $length);
        } while (strlen($string) < $length);
        return $string;
    }
627194
public function format(string $format) : string
    {
        // Replace microseconds first so they become literals.
        // Ignore any escaped microsecond identifiers.
        $format = preg_replace_callback(
            // Starting at the start of the string or the first non % character,
            // consume pairs of % characters (effectively consuming all escaped %s)
            // and finally match the string %u.
            '/((?:^|[^%])(?:%{2})*)(%u)/',
            function (array $matches) {
                return $matches[1] . $this->microseconds;
            },
            $format
        );

        $format = $this->wrapped->format($format);
        
        return $format;
    }
1168437
public function formatString($string, $format) {

        $fmt = str_replace("_", "%s", $format);
        $str = str_split($string);

        return vsprintf($fmt, $str);
    }
1124344
public function generateRandomString($len = 32) {
		$chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
		$max = strlen($chars) - 1;

		$strArr = [];
		for($i = 0; $i < $len; $i++) {
			$strArr[] = $chars[mt_rand(0, $max)];
		}

		return implode($strArr);
	}
562163
public static function getRand($len = 12, $onlyNum = false)
    {
        $chars = $onlyNum ? '0123456789' : 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        mt_srand((double)microtime() * 1000000 * getmypid());
        $return = '';
        while(strlen($return) < $len){
            $return .= substr($chars, (mt_rand() % strlen($chars)), 1);
        }

        return $return;
    }
85545
public static function generateRandomAlphanumericString($length = 8)
    {
        $string = '';
        for ($i=0; $i < $length; $i++) {
            $char = '';
            switch (rand(0, 2)) {
                //A-Z
                case 0:
                    $char = chr(rand(65, 90));
                    break;
                //a-z
                case 1:
                    $char = chr(rand(97, 122));
                    break;
                //0-9
                case 2:
                    $char = (string) rand(0, 9);
                    break;

            }
            $string .= $char;
        }

        return $string;
    }
756018
public function format($format)
    {
        $pad    = false;
        $rChar  = 'hmsfHMS';
        $string = $this->format = $format;
        $string = static::encode($string, $rChar);

        // Perform rounding.
        $this->round = static::maxRound($format);

        // Decimal years, weeks, days, hours, minutes, and seconds
        static::fmtRep('Y', $string, $this->years);
        static::fmtRep('W', $string, $this->weeks);
        static::fmtRep('D', $string, $this->days);
        static::fmtRep('H', $string, $this->hours);
        static::fmtRep('M', $string, $this->min);
        static::fmtRep('S', $string, $this->sec);

        // Leading zeros h m s
        $string = str_replace('0h', sprintf('%02d', $this->h), $string);
        $string = str_replace('0m', sprintf('%02d', $this->m), $string);
        $string = str_replace('0s', sprintf('%02d', $this->s), $string);

        // No leading zeros, h m s
        $string = str_replace('h', $this->h, $string);
        $string = str_replace('m', $this->m, $string);
        $string = str_replace('s', $this->s, $string);

        // Fractional seconds.
        if (preg_match_all('/([0-9])f/', $string, $m)) {
            for ($i = 0; $i < count($m[0]); $i++) {
                $f = substr($this->f, 0, $m[1][$i]);

                if ($pad) {
                    $f      = str_pad($f, $m[1][$i], '0');
                    $string = str_replace($m[0][$i], $f, $string);
                } else {
                    if ($f == 0) {
                        $string = str_replace('.' . $m[0][$i], '', $string);
                        $string = str_replace($m[0][$i], '', $string);
                    } else {
                        $string = str_replace($m[0][$i], $f, $string);
                    }
                }
            }
        }

        return static::decode($string, $rChar);
    }
729063
function printFormatted(string $format): int {
		$args = func_get_args ();
		$s = call_user_func_array ( 'sprintf', $args );
		return $this->write ( $s );
	}