当前位置: 首页>>代码示例>>PHP>>正文


PHP lcg_value函数代码示例

本文整理汇总了PHP中lcg_value函数的典型用法代码示例。如果您正苦于以下问题:PHP lcg_value函数的具体用法?PHP lcg_value怎么用?PHP lcg_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了lcg_value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: onActivate

 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $entity = null;
     $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
     if (!$chunk instanceof FullChunk) {
         return false;
     }
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX() + 0.5), new Double("", $block->getY()), new Double("", $block->getZ() + 0.5)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)])]);
     $entity = Entity::createEntity($this->meta, $chunk, $nbt);
     if ($entity instanceof Entity) {
         if ($player->isSurvival()) {
             --$this->count;
         }
         $entity->spawnToAll();
         return true;
     }
     return false;
 }
开发者ID:mattiasaxelsson,项目名称:PocketMine-MP,代码行数:18,代码来源:SpawnEgg.php

示例2: onActivate

 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->getId() == Block::MONSTER_SPAWNER) {
         return true;
     } else {
         $entity = null;
         $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
         if (!$chunk instanceof FullChunk) {
             return false;
         }
         $nbt = new CompoundTag("", ["Pos" => new EnumTag("Pos", [new DoubleTag("", $block->getX() + 0.5), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ() + 0.5)]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
         if ($this->hasCustomName()) {
             $nbt->CustomName = new StringTag("CustomName", $this->getCustomName());
         }
         $entity = Entity::createEntity($this->meta, $chunk, $nbt);
         if ($entity instanceof Entity) {
             if ($player->isSurvival()) {
                 --$this->count;
             }
             $entity->spawnToAll();
             return true;
         }
     }
     return false;
 }
开发者ID:PepbookPvP,项目名称:Genisys,代码行数:25,代码来源:SpawnEgg.php

示例3: __construct

 /**
  * Constructs the object
  * @param string $query The query
  * @param string $query The query before the redirect (e.g. oprobiu before the automatic redirect to oprobriu)
  * @param int $searchType The seach type
  * @param boolean $redirect If true, then the result is a redirect [OPTIONAL]
  * @param Definition[] $results The results [OPTIONAL]
  * @access public
  * @return void
  **/
 public function __construct($query, $queryBeforeRedirect, $searchType, $redirect = false, &$results = null)
 {
     if (!Config::get('global.logSearch') || lcg_value() > Config::get('global.logSampling')) {
         $this->query = null;
         return false;
     }
     $this->query = $query;
     $this->queryBeforeRedirect = $queryBeforeRedirect;
     $this->searchType = $searchType;
     if (session_variableExists('user')) {
         $this->registeredUser = 'y';
         $this->preferences = $_SESSION['user']->preferences;
     } else {
         $this->registeredUser = 'n';
         $this->preferences = session_getCookieSetting('anonymousPrefs');
     }
     $this->skin = session_getSkin();
     $this->resultCount = count($results);
     $this->redirect = $redirect ? 'y' : 'n';
     $this->resultList = '';
     if ($results != null) {
         $numResultsToLog = min(count($results), Config::get('global.logResults'));
         $this->resultList = '';
         for ($i = 0; $i < $numResultsToLog; $i++) {
             $this->resultList .= ($this->resultList ? ',' : '') . $results[$i]->id;
         }
     }
 }
开发者ID:florinp,项目名称:dexonline,代码行数:38,代码来源:Log.php

示例4: sa

function sa($members)
{
    $T = 100.0;
    $now_temp = 10000;
    $n = count($members);
    $status = 0;
    $best = 1000000000;
    while ($T > 0) {
        do {
            $t1 = rand(0, $n - 1);
            $t2 = rand(0, $n - 1);
        } while ($t1 == $t2);
        $now = sqr(abs($members[$t1]['chosen1'] - $t1)) + sqr(abs($members[$t2]['chosen1'] - $t2));
        $new = sqr(abs($members[$t1]['chosen1'] - $t2)) + sqr(abs($members[$t2]['chosen1'] - $t1));
        if ($new < $now || lcg_value() <= exp(($now - $new) / $T)) {
            $temp = $members[$t1];
            $members[$t1] = $members[$t2];
            $members[$t2] = $temp;
            $status += $new - $now;
            if ($status < $best) {
                $res = $members;
            }
        }
        $T -= 0.02;
    }
    return $res;
}
开发者ID:fei960922,项目名称:ACM_Website_2014_PHP,代码行数:27,代码来源:logistics_model.php

示例5: generate

 public static function generate($length = 10, $charlist = '0-9a-z')
 {
     $charlist = str_shuffle(preg_replace_callback('#.-.#', function ($m) {
         return implode('', range($m[0][0], $m[0][2]));
     }, $charlist));
     $chLen = strlen($charlist);
     if (function_exists('openssl_random_pseudo_bytes') && (PHP_VERSION_ID >= 50400 || !defined('PHP_WINDOWS_VERSION_BUILD'))) {
         $rand3 = openssl_random_pseudo_bytes($length);
     }
     if (empty($rand3) && function_exists('mcrypt_create_iv') && (PHP_VERSION_ID >= 50307 || !defined('PHP_WINDOWS_VERSION_BUILD'))) {
         // PHP bug #52523
         $rand3 = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
     }
     if (empty($rand3) && @is_readable('/dev/urandom')) {
         $rand3 = file_get_contents('/dev/urandom', false, null, -1, $length);
     }
     if (empty($rand3)) {
         static $cache;
         $rand3 = $cache ?: ($cache = md5(serialize($_SERVER), true));
     }
     $s = '';
     $rand = null;
     $rand2 = null;
     for ($i = 0; $i < $length; $i++) {
         if ($i % 5 === 0) {
             list($rand, $rand2) = explode(' ', microtime());
             $rand += lcg_value();
         }
         $rand *= $chLen;
         $s .= $charlist[($rand + $rand2 + ord($rand3[$i % strlen($rand3)])) % $chLen];
         $rand -= (int) $rand;
     }
     return $s;
 }
开发者ID:edde-framework,项目名称:edde,代码行数:34,代码来源:RandomUtils.php

示例6: createBundleMock

 /**
  * @return BundleInterface|\PHPUnit_Framework_MockObject_MockObject
  */
 private function createBundleMock()
 {
     $bundleMock = $this->getMock('Symfony\\Component\\HttpKernel\\Bundle\\BundleInterface');
     $bundleMock->expects($this->any())->method('getNamespace')->will($this->returnValue('Sonata\\AdminBundle\\Tests\\Fixtures'));
     $bundleMock->expects($this->any())->method('getPath')->will($this->returnValue(sprintf('%s/%s', sys_get_temp_dir(), lcg_value())));
     return $bundleMock;
 }
开发者ID:saberyounis,项目名称:Sonata-Project,代码行数:10,代码来源:AdminGeneratorTest.php

示例7: random_float

function random_float($min, $max)
{
    $val = round($min + lcg_value() * abs($max - $min), 3);
    $bal = round(fmod($val, 0.005), 3);
    $val = $val - $bal;
    echo $val;
}
开发者ID:ksm0814,项目名称:roulette,代码行数:7,代码来源:randomizer.php

示例8: generateId

 /**
  * Генерация ид с жизнью до 35 лет для signed и 70 unsigned
  *
  * @param int $id
  *   Идентификатор, по которому идет парцирование данных, если не указан,
  *   то выбирается случайное число
  * @return int
  */
 protected static function generateId($id = 0)
 {
     // Пытаемся получить метку и сгенерировать ид
     if ($epoch = config('common.epoch')) {
         return (floor(microtime(true) * 1000 - $epoch) << 23) + (mt_rand(0, 4095) << 13) + ($id ? $id : lcg_value() * 10000000) % 1024;
     }
     return 0;
 }
开发者ID:dmitrykuzmenkov,项目名称:kisscore-plugin-Model,代码行数:16,代码来源:IdTrait.php

示例9: __construct

 /**
  * Initializes a new instance of this class.
  *
  * @param float $min The minimum value.
  * @param float $max The maximum value.
  * @param float $decimals The amount of decimals to round to.
  */
 public function __construct($min = 0.0, $max = 1.0, $decimals = 0)
 {
     $value = $min + lcg_value() * abs($max - $min);
     if ($decimals != 0) {
         $value = round($value, $decimals);
     }
     parent::__construct($value);
 }
开发者ID:nextflow,项目名称:nextflow-php,代码行数:15,代码来源:RandomFloatVariable.php

示例10: getRandNumber

 function getRandNumber($min, $max)
 {
     if ($min > $max) {
         $temp = $min;
         $min = $max;
         $max = $temp;
     }
     return $min + lcg_value() * abs($max - $min);
 }
开发者ID:0-php,项目名称:AI,代码行数:9,代码来源:ep.class.php

示例11: generate

	/**
	 * Generate random string.
	 * @param  int
	 * @param  string
	 * @return string
	 */
	public static function generate($length = 10, $charlist = '0-9a-z')
	{
		$charlist = count_chars(preg_replace_callback('#.-.#', function ($m) {
			return implode('', range($m[0][0], $m[0][2]));
		}, $charlist), 3);
		$chLen = strlen($charlist);

		if ($length < 1) {
			return ''; // mcrypt_create_iv does not support zero length
		} elseif ($chLen < 2) {
			return str_repeat($charlist, $length); // random_int does not support empty interval
		}

		$res = '';
		if (PHP_VERSION_ID >= 70000) {
			for ($i = 0; $i < $length; $i++) {
				$res .= $charlist[random_int(0, $chLen - 1)];
			}
			return $res;
		}

		$windows = defined('PHP_WINDOWS_VERSION_BUILD');
		$bytes = '';
		if (function_exists('openssl_random_pseudo_bytes')
			&& (PHP_VERSION_ID >= 50400 || !defined('PHP_WINDOWS_VERSION_BUILD')) // slow in PHP 5.3 & Windows
		) {
			$bytes = openssl_random_pseudo_bytes($length, $secure);
			if (!$secure) {
				$bytes = '';
			}
		}
		if (strlen($bytes) < $length && function_exists('mcrypt_create_iv') && (PHP_VERSION_ID >= 50307 || !$windows)) { // PHP bug #52523
			$bytes = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
		}
		if (strlen($bytes) < $length && !$windows && @is_readable('/dev/urandom')) {
			$bytes = file_get_contents('/dev/urandom', FALSE, NULL, -1, $length);
		}
		if (strlen($bytes) < $length) {
			$rand3 = md5(serialize($_SERVER), TRUE);
			$charlist = str_shuffle($charlist);
			for ($i = 0; $i < $length; $i++) {
				if ($i % 5 === 0) {
					list($rand1, $rand2) = explode(' ', microtime());
					$rand1 += lcg_value();
				}
				$rand1 *= $chLen;
				$res .= $charlist[($rand1 + $rand2 + ord($rand3[$i % strlen($rand3)])) % $chLen];
				$rand1 -= (int) $rand1;
			}
			return $res;
		}

		for ($i = 0; $i < $length; $i++) {
			$res .= $charlist[($i + ord($bytes[$i])) % $chLen];
		}
		return $res;
	}
开发者ID:nakoukal,项目名称:fakturace,代码行数:63,代码来源:Random.php

示例12: dropExpOrb__api200

 public static function dropExpOrb__api200(Position $source, $exp = 1, Vector3 $motion = \null, $delay = 40)
 {
     $motion = $motion === \null ? new Vector3(\lcg_value() * 0.2 - 0.1, 0.4, \lcg_value() * 0.2 - 0.1) : $motion;
     $entity = Entity::createEntity("ExperienceOrb", $source->getLevel()->getChunk($source->getX() >> 4, $source->getZ() >> 4, \true), new \pocketmine\nbt\tag\CompoundTag("", ["Pos" => new \pocketmine\nbt\tag\ListTag("Pos", [new \pocketmine\nbt\tag\DoubleTag("", $source->getX()), new \pocketmine\nbt\tag\DoubleTag("", $source->getY()), new \pocketmine\nbt\tag\DoubleTag("", $source->getZ())]), "Motion" => new \pocketmine\nbt\tag\ListTag("Motion", [new \pocketmine\nbt\tag\DoubleTag("", $motion->x), new \pocketmine\nbt\tag\DoubleTag("", $motion->y), new \pocketmine\nbt\tag\DoubleTag("", $motion->z)]), "Rotation" => new \pocketmine\nbt\tag\ListTag("Rotation", [new \pocketmine\nbt\tag\FloatTag("", \lcg_value() * 360), new \pocketmine\nbt\tag\FloatTag("", 0)]), "Health" => new \pocketmine\nbt\tag\ShortTag("Health", 20), "PickupDelay" => new \pocketmine\nbt\tag\ShortTag("PickupDelay", $delay)]));
     if ($entity instanceof ExperienceOrb) {
         $entity->setExp($exp);
     }
     $entity->spawnToAll();
 }
开发者ID:Gumbrat,项目名称:PlayHarder,代码行数:9,代码来源:ExperienceSystem.php

示例13: randomBytes

function randomBytes($length = 16, $secure = true, $raw = true, $startEntropy = "", &$rounds = 0, &$drop = 0)
{
    static $lastRandom = "";
    $output = "";
    $length = abs((int) $length);
    $secureValue = "";
    $rounds = 0;
    $drop = 0;
    while (!isset($output[$length - 1])) {
        //some entropy, but works ^^
        $weakEntropy = array(is_array($startEntropy) ? implode($startEntropy) : $startEntropy, serialize(stat(__FILE__)), __DIR__, PHP_OS, microtime(), (string) lcg_value(), (string) PHP_MAXPATHLEN, PHP_SAPI, (string) PHP_INT_MAX . "." . PHP_INT_SIZE, serialize($_SERVER), serialize(get_defined_constants()), get_current_user(), serialize(ini_get_all()), (string) memory_get_usage() . "." . memory_get_peak_usage(), php_uname(), phpversion(), extension_loaded("gmp") ? gmp_strval(gmp_random(4)) : microtime(), zend_version(), (string) getmypid(), (string) getmyuid(), (string) mt_rand(), (string) getmyinode(), (string) getmygid(), (string) rand(), function_exists("zend_thread_id") ? (string) zend_thread_id() : microtime(), var_export(@get_browser(), true), function_exists("getrusage") ? @implode(getrusage()) : microtime(), function_exists("sys_getloadavg") ? @implode(sys_getloadavg()) : microtime(), serialize(get_loaded_extensions()), sys_get_temp_dir(), (string) disk_free_space("."), (string) disk_total_space("."), uniqid(microtime(), true), file_exists("/proc/cpuinfo") ? file_get_contents("/proc/cpuinfo") : microtime());
        shuffle($weakEntropy);
        $value = hash("sha512", implode($weakEntropy), true);
        $lastRandom .= $value;
        foreach ($weakEntropy as $k => $c) {
            //mixing entropy values with XOR and hash randomness extractor
            $value ^= hash("sha256", $c . microtime() . $k, true) . hash("sha256", mt_rand() . microtime() . $k . $c, true);
            $value ^= hash("sha512", (string) lcg_value() . $c . microtime() . $k, true);
        }
        unset($weakEntropy);
        if ($secure === true) {
            $strongEntropyValues = array(is_array($startEntropy) ? hash("sha512", $startEntropy[($rounds + $drop) % count($startEntropy)], true) : hash("sha512", $startEntropy, true), file_exists("/dev/urandom") ? fread(fopen("/dev/urandom", "rb"), 64) : str_repeat("", 64), (function_exists("openssl_random_pseudo_bytes") and version_compare(PHP_VERSION, "5.3.4", ">=")) ? openssl_random_pseudo_bytes(64) : str_repeat("", 64), function_exists("mcrypt_create_iv") ? mcrypt_create_iv(64, MCRYPT_DEV_URANDOM) : str_repeat("", 64), $value);
            $strongEntropy = array_pop($strongEntropyValues);
            foreach ($strongEntropyValues as $value) {
                $strongEntropy = $strongEntropy ^ $value;
            }
            $value = "";
            //Von Neumann randomness extractor, increases entropy
            $bitcnt = 0;
            for ($j = 0; $j < 64; ++$j) {
                $a = ord($strongEntropy[$j]);
                for ($i = 0; $i < 8; $i += 2) {
                    $b = ($a & 1 << $i) > 0 ? 1 : 0;
                    if ($b != (($a & 1 << $i + 1) > 0 ? 1 : 0)) {
                        $secureValue |= $b << $bitcnt;
                        if ($bitcnt == 7) {
                            $value .= chr($secureValue);
                            $secureValue = 0;
                            $bitcnt = 0;
                        } else {
                            ++$bitcnt;
                        }
                        ++$drop;
                    } else {
                        $drop += 2;
                    }
                }
            }
        }
        $output .= substr($value, 0, min($length - strlen($output), $length));
        unset($value);
        ++$rounds;
    }
    $lastRandom = hash("sha512", $lastRandom, true);
    return $raw === false ? bin2hex($output) : $output;
}
开发者ID:Kengaming1st,项目名称:Secure-PHP-Random-Bytes,代码行数:56,代码来源:randomBytes.php

示例14: Neuron

 public function Neuron($nInputs)
 {
     $this->numInputs = $nInputs;
     for ($i = 0; $i < $nInputs + 1; $i++) {
         // The last item of the array is to store the bias
         // Initialize with random float between -1 and 1
         $this->weights[] = lcg_value() * 2 - 1;
         //$this->weights[] = rand();
     }
 }
开发者ID:francoisvermaut,项目名称:fv,代码行数:10,代码来源:Neuron.php

示例15: reset

 public function reset()
 {
     // Random initial position
     $this->posx = lcg_value() * $fieldmaxx;
     $this->posy = lcg_value() * $fieldmaxy;
     $this->lookatx = 0;
     $this->lookaty = 0;
     // Random initial rotation
     $this->rotation = lcg_value() * pi();
     $this->fitness = 0;
 }
开发者ID:francoisvermaut,项目名称:fv,代码行数:11,代码来源:MineSweeper.php


注:本文中的lcg_value函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。