本文整理汇总了PHP中Random类的典型用法代码示例。如果您正苦于以下问题:PHP Random类的具体用法?PHP Random怎么用?PHP Random使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Random类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: 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('account', $account, Config::get('regex.account'))) {
$response['info'] = '学号格式有误!';
} elseif (!Safe::checkTry('pwd_email_' . $account)) {
$response['info'] = '尝试次数过多,临时封禁!';
} elseif (!($Printer = PrinterModel::where('account', $account)->field('id,email')->find())) {
$response['info'] = '尚未注册,或者账号错误';
} elseif (empty($Printer['email'])) {
$response['info'] = '未绑定邮箱,或邮箱不存在';
} elseif ($Printer['email'] != $email) {
$response['info'] = '绑定邮箱不一致,或者邮箱错误';
} elseif (!Mail::findPwd($email, $code = Random::code(6))) {
$response['info'] = '邮件发送出错,请联系我们!';
} else {
/*发送成功*/
$find = ['id' => $user['id'], 'account' => $account, 'code' => strtoupper($code)];
Session::set('find_info_p', $find);
Safe::del('pwd_email_' . $account);
$response['status'] = 1;
$response['info'] = '验证邮件已发送!';
}
$this->response = $response;
}
开发者ID:derek-chow,项目名称:YunYinService,代码行数:32,代码来源:Password.php
示例17: get
public static function get()
{
if (!isset(self::$rand_seeder)) {
//if ((PHP_SAPI == 'cli') or defined('STDIN')) {
if (IS_CLI) {
// CodeIgniter specific implementation.
self::$rand_seeder = Random::int(0, 2147483647);
} else {
//if (function_exists('get_instance')) {
// CodeIgniter specific implementation.
$ci = get_instance();
$ci->load->library('session');
$session_data = $ci->session->userdata('rand_seeder');
if (!is_null($session_data)) {
self::$rand_seeder = $session_data;
} else {
self::$rand_seeder = Random::int(0, 2147483647);
$ci->session->set_userdata('rand_seeder', self::$rand_seeder);
}
//} else {
// if (isset($_SESSION['rand_seeder'])) {
// self::$rand_seeder = $_SESSION['rand_seeder'];
// } else {
// self::$rand_seeder = rand();
// $_SESSION['rand_seeder'] = self::$rand_seeder;
// }
//}
}
}
return self::$rand_seeder;
}
开发者ID:Qnatz,项目名称:starter-public-edition-4,代码行数:31,代码来源:RandSeeder.php
示例18: add_to_gallery
function add_to_gallery()
{
$gallery_peer = new GalleryPeer();
$gallery = $gallery_peer->find_by_id(Params::get("id_gallery"));
$collection_peer = new GalleryCollectionPeer();
$gallery_collection = $collection_peer->find_by_id($gallery->id_gallery_collection);
$full_folder_path = GalleryCollectionController::GALLERY_COLLECTION_ROOT_DIR . $gallery_collection->folder . "/" . $gallery->folder;
if (Upload::isUploadSuccessful("file")) {
$filename = Random::newHexString() . "_" . Upload::getRealFilename("file");
$gallery_dir = new Dir($full_folder_path);
$uploaded_img = Upload::saveTo("file", $gallery_dir, $filename);
if (isset(Config::instance()->GALLERY_RESIZE_BY_WIDTH)) {
image_w($uploaded_img->getPath(), Config::instance()->GALLERY_RESIZE_BY_WIDTH);
} else {
if (isset(Config::instance()->GALLERY_RESIZE_BY_HEIGHT)) {
image_h($uploaded_img->getPath(), Config::instance()->GALLERY_RESIZE_BY_HEIGHT);
}
}
$peer = new GalleryImagePeer();
$do = $peer->new_do();
$peer->setupByParams($do);
$do->image_name = $filename;
$peer->save($do);
return Redirect::success();
} else {
Flash::error(Upload::getUploadError("file"));
return Redirect::failure();
}
}
开发者ID:mbcraft,项目名称:frozen,代码行数:29,代码来源:GalleryImageController.class.php
示例19: testUniqueString
/**
* Random strings should be different
*/
public function testUniqueString()
{
$value1 = Random::getUniqueString();
$value2 = Random::getUniqueString();
$this->assertInternalType('string', $value1);
$this->assertInternalType('string', $value2);
$this->assertNotEquals($value1, $value2);
}
开发者ID:messyOne,项目名称:Loo-Framework,代码行数:11,代码来源:RandomTest.php
示例20: makeToken
protected function makeToken()
{
$pkg_id = $this->package->getId();
$token = Random::string(32);
// tokenは60秒有効
mfwMemcache::set(self::TOKEN_KEY_PREFIX . $token, $pkg_id, 60);
return $token;
}
开发者ID:kzfk,项目名称:emlauncher,代码行数:8,代码来源:installActions.php
注:本文中的Random类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论