當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Random類代碼示例

本文整理匯總了PHP中Random的典型用法代碼示例。如果您正苦於以下問題:PHP Random類的具體用法?PHP Random怎麽用?PHP Random使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Random類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: growTree

 public static function growTree(Level $level, Vector3 $pos, Random $random, $type = 0)
 {
     switch ($type & 0x3) {
         case SaplingBlock::SPRUCE:
             if ($random->nextRange(0, 1) === 1) {
                 $tree = new SpruceTreeObject();
             } else {
                 $tree = new PineTreeObject();
             }
             break;
         case SaplingBlock::BIRCH:
             $tree = new SmallTreeObject();
             $tree->type = SaplingBlock::BIRCH;
             break;
         case SaplingBlock::JUNGLE:
             $tree = new SmallTreeObject();
             $tree->type = SaplingBlock::JUNGLE;
             break;
         default:
         case SaplingBlock::OAK:
             /*if($random->nextRange(0, 9) === 0){
             			$tree = new BigTreeObject();
             		}else{*/
             $tree = new SmallTreeObject();
             //}
             break;
     }
     if ($tree->canPlaceObject($level, $pos, $random)) {
         $tree->placeObject($level, $pos, $random);
     }
 }
開發者ID:ungarscool1,項目名稱:Multicraft,代碼行數:31,代碼來源:TreeObject.php

示例2: random

 public function random(array $generators, callable $assertion)
 {
     $shrinker = new Random($generators, $assertion);
     if ($this->options['timeLimit'] !== null) {
         $shrinker->setTimeLimit(FixedTimeLimit::realTime($this->options['timeLimit']));
     }
     return $shrinker;
 }
開發者ID:nicoder,項目名稱:eris,代碼行數:8,代碼來源:ShrinkerFactory.php

示例3: inPercentile

 /**
  * Generates a random number and returns a boolean representing whether it is within a given percentile.
  * For example: inPercentile(0.1) is equivalent to rand(1, 1000) == 1.
  *
  * @param float $perc The percentile to evaluate, can also be < 1.
  * @return boolean
  */
 public function inPercentile($perc)
 {
     if ($this->nextRandomNumber >= 0 && $this->nextRandomNumber <= 100 && $perc >= 0 && $perc <= 100) {
         $rand = $this->nextRandomNumber;
         $this->nextRandomNumber = -1;
         return $rand <= $perc;
     }
     return $this->realRandom->inPercentile($perc);
 }
開發者ID:plista,項目名稱:core,代碼行數:16,代碼來源:MockRandom.php

示例4: populate

 public function populate(Level $level, $chunkX, $chunkZ, Random $random)
 {
     if ($random->nextRange(0, $this->waterOdd) === 0) {
         $v = new Vector3($random->nextRange($chunkX << 4, ($chunkX << 4) + 16), $random->nextRange(0, 128), $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16));
         $pond = new PondObject($random, new WaterBlock());
         if ($pond->canPlaceObject($level, $v)) {
             $pond->placeObject($level, $v);
         }
     }
 }
開發者ID:ungarscool1,項目名稱:Multicraft,代碼行數:10,代碼來源:PondPopulator.php

示例5: growGrass

 public static function growGrass(Level $level, Vector3 $pos, Random $random, $count = 15, $radius = 10)
 {
     $arr = array(BlockAPI::get(DANDELION, 0), BlockAPI::get(CYAN_FLOWER, 0), BlockAPI::get(TALL_GRASS, 1), BlockAPI::get(TALL_GRASS, 1), BlockAPI::get(TALL_GRASS, 1), BlockAPI::get(TALL_GRASS, 1));
     $arrC = count($arr) - 1;
     for ($c = 0; $c < $count; ++$c) {
         $x = $random->nextRange($pos->x - $radius, $pos->x + $radius);
         $z = $random->nextRange($pos->z - $radius, $pos->z + $radius);
         if ($level->level->getBlockID($x, $pos->y + 1, $z) === AIR and $level->level->getBlockID($x, $pos->y, $z) === GRASS) {
             $t = $arr[$random->nextRange(0, $arrC)];
             $level->setBlockRaw(new Vector3($x, $pos->y + 1, $z), $t);
         }
     }
 }
開發者ID:ungarscool1,項目名稱:Multicraft,代碼行數:13,代碼來源:TallGrassObject.php

示例6: populate

 public function populate(Level $level, $chunkX, $chunkZ, Random $random)
 {
     foreach ($this->oreTypes as $type) {
         $ore = new OreObject($random, $type);
         for ($i = 0; $i < $ore->type->clusterCount; ++$i) {
             $x = $random->nextRange($chunkX << 4, ($chunkX << 4) + 16);
             $y = $random->nextRange($ore->type->minHeight, $ore->type->maxHeight);
             $z = $random->nextRange($chunkZ << 4, ($chunkZ << 4) + 16);
             if ($ore->canPlaceObject($level, $x, $y, $z)) {
                 $ore->placeObject($level, new Vector3($x, $y, $z));
             }
         }
     }
 }
開發者ID:ungarscool1,項目名稱:Multicraft,代碼行數:14,代碼來源:OrePopulator.php

示例7: executeDelete_confirm

 public function executeDelete_confirm()
 {
     $token = Random::string(32);
     mfwSession::set(self::SESKEY_TOKEN, $token);
     $parma = array('token' => $token);
     return $this->build($parma);
 }
開發者ID:kzfk,項目名稱:emlauncher,代碼行數:7,代碼來源:deleteActions.php

示例8: actionIndex

 public function actionIndex()
 {
     $newsList = array();
     $newsList = Random::getRandList();
     require_once ROOT . '/views/news/index.php';
     return true;
 }
開發者ID:xcorn,項目名稱:someblog,代碼行數:7,代碼來源:RandomController.php

示例9: getContext

	/**
	 *	@interface ContextService
	**/
	public function getContext($model){
		$conn = $model['conn'];
		$stgname = $conn->escape($model['stgname']);
		$filename = $conn->escape($model['filename']);
		$mime = $conn->escape($model['mime']);
		$owner = $model['owner'];
		$access = $model['access'];
		$group = $model['group'];
		$dirid = $conn->escape($model['dirid']);
		
		$stgid = Random::getString(128); 
		$ts = Time::getTime();
		
		$query = "insert into storages (stgid, stgname, filename, mime, owner, access, group, ctime, atime, mtime, dirid) values ('$stgid', '$stgname', '$filename', '$mime', $owner, $access, $group, $ts, $ts, $ts, '$dirid')";
		$result = $conn->getResult($query);
		
		if($result === false){
			$model['valid'] = false;
			$model['msg'] = 'Error in Database @getContext/storage.create';
			return $model;
		}
		
		$model['valid'] = true;
		$model['stgid'] = $stgid;
		return $model;
	}
開發者ID:nimitz92,項目名稱:enhanCSE-core,代碼行數:29,代碼來源:StorageCreateContext.class.php

示例10: POST_emailAction

 /**
  * 通過郵箱找回密碼
  * @method POST_emailAction
  * @author NewFuture
  */
 public function POST_emailAction()
 {
     $response['status'] = 0;
     if (!Input::post('email', $email, 'email')) {
         $response['info'] = '郵箱格式有誤或者不支持!';
     } elseif (!Input::post('number', $number, 'card')) {
         $response['info'] = '學號格式有誤!';
     } elseif (!Safe::checkTry('pwd_email_' . $number)) {
         $response['info'] = '嘗試次數過多,臨時封禁!';
     } elseif (!($user = UserModel::where('number', $number)->field('id,name,email')->find())) {
         $response['info'] = '尚未注冊,或者學號錯誤';
     } elseif (empty($user['email'])) {
         $response['info'] = '未綁定郵箱,或者學號錯誤';
     } elseif (Encrypt::decryptEmail($user['email']) != $email) {
         $response['info'] = '綁定郵箱不一致,或者郵箱錯誤';
     } elseif (!Mail::findPwd($email, $code = Random::code(6), $user['name'])) {
         $response['info'] = '郵件發送出錯,請聯係我們!';
     } else {
         /*發送成功*/
         $findPwd = ['id' => $user['id'], 'number' => $number, 'code' => strtoupper($code)];
         Session::set('find_info', $findPwd);
         Safe::del('pwd_email_' . $number);
         $response['status'] = 1;
         $response['info'] = '找回驗證碼已發送到' . $email;
     }
     $this->response = $response;
 }
開發者ID:derek-chow,項目名稱:YunYinService,代碼行數:32,代碼來源:Password.php

示例11: addSession

		public function addSession($mysql, $uid) {
		
		$time = Time::getTime();
		$session= new Session;
		$random = Random::getString(32);
		$expiry = $time + 30*24*60*60;
		$session->read($uid,$time,$expiry);
			switch($session->insert($mysql, $random)) {
				case Session::DATABASE_ERROR :
				{
					echo "<p>A Database error has occured.</p>";
					return;
				}
				case Session::INVALID_DATA :
				{
					echo "<p>Invalid operation requested.</p>";
					return;
				}
				case Session::INSERT_SUCCESS : 
				{
					
					return $random;
				}
				default :
					break;
			}
	}
開發者ID:nimitz92,項目名稱:lcm,代碼行數:27,代碼來源:SessionManager.class.php

示例12: getContext

	/**
	 *	@interface ContextService
	**/
	public function getContext($model){
		$conn = $model['conn'];
		$uid = $model['uid'];
		$interval = $model['interval'];

		$sessionid = Random::getString(32); 
		$ts = Time::getTime();
		$ts_exp = $ts + $interval;
		
		$query = "delete from sessions where expiry < $ts;";
		$conn->getResult($query, true);
		
		$query = "insert into sessions values('$sessionid', $uid, $ts, $ts_exp);";
		$result = $conn->getResult($query, true);
		
		if($result === false){
			$model['valid'] = false;
			$model['msg'] = 'Error in Database @getContext/session.create';
			return $model;
		}
		
		$model['valid'] = true;
		$model['sessionid'] = $sessionid;

		return $model;
	}
開發者ID:nimitz92,項目名稱:enhanCSE-core,代碼行數:29,代碼來源:SessionCreateContext.class.php

示例13: generate

 /**
  * Generates an RFC 4122-compliant version 4 UUID.
  *
  * @return string The string representation of an RFC 4122-compliant, version 4 UUID.
  * @link http://www.ietf.org/rfc/rfc4122.txt RFC 4122: UUID URN Namespace
  */
 public static function generate()
 {
     $uuid = Random::GenerateBytes(16);
     $uuid[6] = chr(ord($uuid[6]) & static::UUID_CLEAR_VER | static::UUID_VERSION_4);
     $uuid[8] = chr(ord($uuid[8]) & static::UUID_CLEAR_VAR | static::UUID_VAR_RFC);
     return join('-', array(bin2hex(substr($uuid, 0, 4)), bin2hex(substr($uuid, 4, 2)), bin2hex(substr($uuid, 6, 2)), bin2hex(substr($uuid, 8, 2)), bin2hex(substr($uuid, 10, 6))));
 }
開發者ID:splitice,項目名稱:radical-basic,代碼行數:13,代碼來源:UUID.php

示例14: getContext

	public function getContext($model){
		$conn = $model['conn'];
		$username = $conn->escape($model['username']);
		$email = $conn->escape($model['email']);
		$subject = $model['subject'];
		$message = $model['message'];
		
		//$newusername = Random::getString(8);
		$password = Random::getString(16);
		$result = $conn->getResult("update users set password=MD5('$username$password') where username='$username' and email='$email';", true);
		
		if($result === false || $result != 1){
			$model['valid'] = false;
			$model['msg'] = 'Error in Database';
			return $model;
		}
		
		$message = str_replace('{username}', $username, $message);
		$message = str_replace('{password}', $password, $message);
		
		$sent = Mail::send($email, $subject, $message);
		
		if($sent === false){
			$model['valid'] = false;
			$model['msg'] = 'Error in Sending Mail';
			return $model;
		}
		
		$model['valid'] = true;
		$model['sent'] = $sent;
		return $model;
	}
開發者ID:nimitz92,項目名稱:enhanCSE-core,代碼行數:32,代碼來源:UserResetContext.class.php

示例15: create_user

 public function create_user($userdata)
 {
     $password = \Arr::get($userdata, 'password', null);
     $email = \Arr::get($userdata, 'email', null);
     if (is_null($password) || is_null($email)) {
         Logger::instance()->log_log_in_attempt(Model_Log_In_Attempt::$ATTEMPT_BAD_CRIDENTIALS, $email);
         throw new LogInFailed(\Lang::get('ethanol.errors.loginInvalid'));
     }
     $user = Auth_Driver::get_core_user($email);
     $security = new Model_User_Security();
     //Generate a salt
     $security->salt = Hasher::instance()->hash(\Date::time(), Random::instance()->random());
     $security->password = Hasher::instance()->hash($password, $security->salt);
     if (\Config::get('ethanol.activate_emails', false)) {
         $keyLength = \Config::get('ethanol.activation_key_length');
         $security->activation_hash = Random::instance()->random($keyLength);
         $user->activated = 0;
         //Send email
         \Package::load('email');
         //Build an array of data that can be passed to the email template
         $emailData = array('email' => $user->email, 'activation_path' => \Str::tr(\Config::get('ethanol.activation_path'), array('key' => $security->activation_hash)));
         $email = \Email::forge()->from(\Config::get('ethanol.activation_email_from'))->to($user->email, $user->username)->subject(\Config::get('ethanol.activation_email_subject'))->html_body(\View::forge('ethanol/activation_email', $emailData))->send();
     } else {
         $user->activated = 1;
         $security->activation_hash = '';
     }
     $user->security = $security;
     $user->save();
     $user->clean_security();
     return $user;
 }
開發者ID:inespons,項目名稱:ethanol,代碼行數:31,代碼來源:Database.php


注:本文中的Random類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。