本文整理匯總了PHP中Random::number方法的典型用法代碼示例。如果您正苦於以下問題:PHP Random::number方法的具體用法?PHP Random::number怎麽用?PHP Random::number使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Random
的用法示例。
在下文中一共展示了Random::number方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: POST_phoneAction
/**
* 發送手機驗證碼
* @method POST_phoneAction
* @author NewFuture
*/
public function POST_phoneAction()
{
$response['status'] = 0;
if (!Input::post('phone', $phone, Config::get('regex.phone'))) {
$response['info'] = '手機號格式有誤或者不支持!';
} elseif (!Input::post('account', $account, Config::get('regex.account'))) {
$response['info'] = '賬號有誤,如果賬號忘記請聯係雲印工作人員';
} elseif (!($Printer = PrinterModel::where('account', $account)->field('id,phone')->find())) {
$response['info'] = '尚未注冊';
} elseif (!Safe::checkTry('pwd_phone_' . $account)) {
$response['info'] = '嘗試次數過多,臨時封禁!';
} elseif (!$Printer['phone'] || $Printer['phone'] != $phone) {
$response['info'] = '綁定手機不一致,或者手機號錯誤';
} elseif (!Sms::findPwd($phone, $code = Random::number(6))) {
$response['info'] = '短信發送出錯,請聯係我們!';
} else {
/*發送成功*/
$find = ['id' => $Printer['id'], 'account' => $account, 'code' => strtoupper($code)];
Session::set('find_info_p', $find);
Safe::del('pwd_phone_' . $account);
$response['status'] = 1;
$response['info'] = '驗證短信已發送';
}
$this->response = $response;
}
示例2: simulate
/**
* Simulates a trading period
*
* @param int $steps
* @param int $drift
* @param float $volatility
* @param bool $start
* @return $this
*/
public function simulate($steps = 8, $drift = 0, $volatility = 0.1, $start = false)
{
$price = $this->price;
if ($start) {
$price = $start;
}
$this->addRun($price);
//TODO CONSIDER GAPS
for ($i = 0; $i < $steps; $i++) {
$growth = exp($drift + $volatility * Random::number());
$price = round($price * pow($growth, 1 / $steps), 2);
$this->addRun($price);
}
$this->price = $price;
return $this;
}
示例3: POST_phoneAction
/**
* 綁定用戶手機,發送驗證碼
* PUT /user/1/phone {phone:"13888888888"}
* @method GET_infoAction
* @param integer $id [description]
* @author NewFuture
*/
public function POST_phoneAction($id = 0)
{
$id = $this->auth($id);
$response['status'] = 0;
if (!Input::post('phone', $phone, 'phone')) {
$response['info'] = '手機號碼無效';
} elseif (UserModel::getByPhone($phone)) {
$response['info'] = '已經綁定過用戶';
} elseif (!Safe::checkTry('bind_phone_' . $id)) {
$response['info'] = '發送次數過多,稍後重試';
} else {
/*手機有效,發送驗證碼*/
$code = Random::number(6);
Session::set('code_phone', [$code => $phone]);
if (Sms::bind($phone, $code)) {
$response['status'] = 1;
$response['info'] = '發送成功[最多可重發5次]';
} else {
$response['info'] = '短信發送出錯[最多可重發5次]';
}
}
$this->response = $response;
}
示例4: numberDec
/**
* 數字編碼並按指定長度補位
* @param $num
* @param int $len
* @return string
*/
public static function numberDec($num, $len = 0)
{
$numStr = strval($num);
$slen = strlen($numStr);
$tagNo = '5';
//沒有補位
$tagYes = '4';
// 已經補位 ,補位後第二個字符為補位長度
if ($len == 0) {
return $tagNo . self::to62($num);
}
if ($len <= $slen) {
return $tagNo . self::to62($numStr);
}
// 補位,補位長度不能操過62
$bl = $len - $slen;
$numStr = Random::number($bl) . $numStr;
return $tagYes . self::to62($bl) . self::to62($numStr);
}