Returns a randomly chosen iOS Calendar User Agent string.
@param  string $min .... minimum version
Format: 'MAJOR.MINOR' (1 dot only)
@return string
@throws \Exception
976534
public static function getCalendarUA($min = '5.0') {
    if (strpos($min, '.') === false && ctype_digit($min)) {
      $mins[0] = $min;
      $mins[1] = 0;
    }
    else {
      $mins = explode('.', $min);
    }
    $builds   = array();
    $versions = array();
    $n        = 0;
    self::populate();
    foreach (self::$BuildVer as $code => $val) {
      $parts = explode('.', $val);
      if ($parts[0] >= $mins[0] && $parts[1] >= $mins[1]) {
        $builds[$n]   = $code;
        $versions[$n] = $val;
        $n++;
      }
    }
    $ran = mt_rand(0, $n - 1);
    $ver = preg_replace('/b\d+$/', '', $versions[$ran]);
    return 'iOS/' . $ver . ' (' . $builds[$ran] . ') dataaccessd/1.0';
  }
1173727
public static function generateRandomInt($min, $max)
    {
        $range = $max - $min;
        $bits = $bytes = $mask = $val = 0;
        while ($range > 0) {
            if ($bits % 8 === 0) {
               ++$bytes;
            }
            ++$bits;
            $range >>= 1;
            $mask = $mask << 1 | 1;
        }
        $valueShift = $min;

        do {
            if ($attempts > 128) {
                throw new \Exception('Could not generate valid random integer');
            }
            $randomByteString = self::generateCryptoKey($bytes);

            $val = 0;
            for ($i = 0; $i < $bytes; ++$i) {
                $val |= ord($randomByteString[$i]) << ($i * 8);
            }

            $val &= $mask;
            $val += $valueShift;

            ++$attempts;

        } while (!is_int($val) || $val > $max || $val < $min);

        return (int) $val;
    }
871206
public function getRandomNumber($min = -1, $max = -1) {
		return (is_int($min) && is_int($max) && $min >= 0 && $max >= 0) ? mt_rand($min, $max) : mt_rand();
	}
904223
public function min($min) {
        $this->check_role = 'min';
        $this->p1 = $min;
        $result = $this->value >= $min;
        $this->checkResult($result);
        return $this;
    }
558031
public static function random($min, $max) {
        $max += 1;
        $range = $max - $min;
        if ($range == 0) return $min; // not so random...
        $log = log($range, 2);
        $bytes = (int) ($log / 8) + 1; // length in bytes
        $bits = (int) $log + 1; // length in bits
        $filter = (int) (1 << $bits) - 1; // set all lower bits to 1
        do {
            $rnd = hexdec(bin2hex(openssl_random_pseudo_bytes($bytes, $s)));
            $rnd = $rnd & $filter; // discard irrelevant bits
        } while ($rnd >= $range);
        return $min + $rnd;
    }
447919
public function toMin(callable $min = null)
    {
        if (null === $min) {
            // can't use min() as $smallest is initially null but actual
            // elements were not checked yet, and min() considers null to always
            // be the minimum value
            $min = function($smallest, $element)
                   {
                       return (null === $smallest || $element < $smallest) ? $element : $smallest;
                   };
        }

        return $this->with($min);
    }
453929
public function match($userAgent = null, $accept = null)
	{
		// Set our agent string.
		if (is_null($userAgent))
		{
			if (isset($_SERVER['HTTP_USER_AGENT']))
			{
				$this->agent = trim($_SERVER['HTTP_USER_AGENT']);
			}
		}
		else
		{
			$this->agent = $userAgent;
		}

		$this->lowerAgent = strtolower($this->agent);

		// Set our accept string.
		if (is_null($accept))
		{
			if (isset($_SERVER['HTTP_ACCEPT']))
			{
				$this->accept = strtolower(trim($_SERVER['HTTP_ACCEPT']));
			}
		}
		else
		{
			$this->accept = strtolower($accept);
		}

		if (!empty($this->agent))
		{
			$this->_setPlatform();

			foreach ($this->regexes as $regex)
			{
				if (preg_match($regex['regex'], $this->agent, $version))
				{
					$this->browser  = strtolower($regex['name']);
					$this->platform = ($regex['platform'] ? $regex['platform'] : $this->platform);
					if (!$this->mobile)
					{
						$this->mobile   = $regex['mobile'];
					}

					if (isset($regex['version']))
					{
						if (preg_match($regex['version'], $this->agent, $ver))
						{
							$version = $ver;
						}
					}

					if (!empty($version) && isset($version[1]))
					{
						$bits = explode('.', $version[1]);

						$this->majorVersion = $bits[0];
						$this->minorVersion = (isset($bits[1]) ? $bits[1] : 0);
					}

					break;
				}
			}
		}
	}
852326
private function min($value, $min)
    {
        if (is_string($value)) {
            $value = strlen($value);
        }

        return $value >= $min;
    }
996823
protected function _getUserAgent()
    {
        $ua = str_replace('%v', self::VERSION, $this->userAgent);
        $ua = str_replace('%m', $this->_getUpdateMethod(), $ua);

        return $ua;
    }
394804
public static function minLen($text, $minLen)
	{
	    if (is_array($minLen)) {
	        if (!isset($minLen['minLen'])) {
	            throw new \InvalidArgumentException('The $minLen argument must have "minLen" key');
	        }
	        $minLen = $minLen['minLen'];
	    }

	    return strlen($text) >= $minLen;
	}
891742
public static function getInstance($userAgent = null, $accept = null)
	{
		$signature = serialize(array($userAgent, $accept));

		if (empty(self::$instances[$signature]))
		{
			self::$instances[$signature] = new self($userAgent, $accept);
		}

		return self::$instances[$signature];
	}
939177
public function getUserAgent(): string
    {
        $userAgent = 'Swoft/' . App::version();
        $userAgent .= ' Swoft/' . SWOOLE_VERSION;
        $userAgent .= ' PHP/' . PHP_VERSION;
        return $userAgent;
    }
1075220
public function rand($min = 0, $max = 0)
	{
		if (!$max)
			$max = getrandmax();

		return $this->registry()->isRegistered(self::REGISTRY_RAND)
			? $this->lookup(self::REGISTRY_RAND)
			: rand($min, $max);
	}
711805
private function createMin(array $defaults): Min
    {
        $options = ['min' => $defaults['min']];

        if (array_key_exists('minMessage', $defaults)) {
            $options['message'] = $defaults['minMessage'];
        }

        return new Min($options);
    }
1044036
public function length($min, $max = null) {
        if (!$this->_isValid) {
            return $this;
        }
        $c = count($this->_unsafeVar);
        if ($c < $min || (null !== $max && $c > $max)) {
            $this->_isValid = false;
        }
        return $this;
    }
1251880
public static function random($min, $max = null)
    {
        if (String::isEmpty($max) ||
            $max > getrandmax()) {
            $max = getrandmax();
        }

        return rand($min, $max);
    }
436103
protected function rand($min, $max)
    {
        $this->seed = md5($this->seed);
        $rand = hexdec(substr($this->seed, 0, 8));
        return ($rand % ($max - $min + 1)) + $min;
    }