本文整理汇总了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);
}
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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);
}
}
}
示例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));
}
}
}
}
示例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);
}
示例8: actionIndex
public function actionIndex()
{
$newsList = array();
$newsList = Random::getRandList();
require_once ROOT . '/views/news/index.php';
return true;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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))));
}
示例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;
}
示例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;
}