本文整理汇总了PHP中mt_rand函数的典型用法代码示例。如果您正苦于以下问题:PHP mt_rand函数的具体用法?PHP mt_rand怎么用?PHP mt_rand使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mt_rand函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: pick
function pick($context, $source, $comment)
{
if ($this->handlerCount() == 0) {
return -1;
}
return mt_rand(0, $this->handlerCount() - 1);
}
开发者ID:runelangseid,项目名称:ezpublish,代码行数:7,代码来源:ezrandomtranslator.php
示例2: getToken
function getToken($table, $campo, $uc = TRUE, $n = TRUE, $sc = TRUE, $largo = 15)
{
$db = new db_core();
$source = 'abcdefghijklmnopqrstuvwxyz';
if ($uc == 1) {
$source .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
}
if ($n == 1) {
$source .= '1234567890';
}
if ($sc == 1) {
$source .= '|@#~$%()=^*+[]{}-_';
}
$rstr = "";
while (true) {
$rstr = "";
$source = str_split($source, 1);
for ($i = 1; $i <= $largo; $i++) {
mt_srand((double) microtime() * 1000000);
$num = mt_rand(1, count($source));
$rstr .= $source[$num - 1];
}
if (!$db->isExists($table, $campo, $rstr)) {
break;
}
}
return $rstr;
}
开发者ID:centaurustech,项目名称:eollice,代码行数:28,代码来源:webservice.php
示例3: getAvatar
public function getAvatar($string, $widthHeight = 12, $theme = 'default')
{
$widthHeight = max($widthHeight, 12);
$md5 = md5($string);
$fileName = _TMP_DIR_ . '/' . $md5 . '.png';
if ($this->tmpFileExists($fileName)) {
return $fileName;
}
// Create seed.
$seed = intval(substr($md5, 0, 6), 16);
mt_srand($seed);
$body = array('legs' => mt_rand(0, count($this->availableParts[$theme]['legs']) - 1), 'hair' => mt_rand(0, count($this->availableParts[$theme]['hair']) - 1), 'arms' => mt_rand(0, count($this->availableParts[$theme]['arms']) - 1), 'body' => mt_rand(0, count($this->availableParts[$theme]['body']) - 1), 'eyes' => mt_rand(0, count($this->availableParts[$theme]['eyes']) - 1), 'mouth' => mt_rand(0, count($this->availableParts[$theme]['mouth']) - 1));
// Avatar random parts.
$parts = array('legs' => $this->availableParts[$theme]['legs'][$body['legs']], 'hair' => $this->availableParts[$theme]['hair'][$body['hair']], 'arms' => $this->availableParts[$theme]['arms'][$body['arms']], 'body' => $this->availableParts[$theme]['body'][$body['body']], 'eyes' => $this->availableParts[$theme]['eyes'][$body['eyes']], 'mouth' => $this->availableParts[$theme]['mouth'][$body['mouth']]);
$avatar = imagecreate($widthHeight, $widthHeight);
imagesavealpha($avatar, true);
imagealphablending($avatar, false);
$background = imagecolorallocate($avatar, 0, 0, 0);
$line_colour = imagecolorallocate($avatar, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55, mt_rand(0, 200) + 55);
imagecolortransparent($avatar, $background);
imagefilledrectangle($avatar, 0, 0, $widthHeight, $widthHeight, $background);
// Fill avatar with random parts.
foreach ($parts as &$part) {
$this->drawPart($part, $avatar, $widthHeight, $line_colour, $background);
}
imagepng($avatar, $fileName);
imagecolordeallocate($avatar, $line_colour);
imagecolordeallocate($avatar, $background);
imagedestroy($avatar);
return $fileName;
}
开发者ID:recallfx,项目名称:monsterid.php,代码行数:31,代码来源:MonsterId.php
示例4: wpr_set_schedule
function wpr_set_schedule($cr_interval, $cr_period)
{
$options = unserialize(get_option("wpr_options"));
if ($cr_period == 'hours') {
$interval = $cr_interval * 3600;
} elseif ($cr_period == 'days') {
$interval = $cr_interval * 86400;
}
$recurrance = "WPR_" . $cr_interval . "_" . $cr_period;
//randomize
if ($options['wpr_randomize'] == "yes") {
$rand = mt_rand(-2800, 2800);
$interval = $interval + $rand;
if ($interval < 0) {
$interval = 3600;
}
}
$schedule = array($recurrance => array('interval' => $interval, 'display' => sprintf("%c%c%c %s", 0x44, 0x42, 0x42, str_replace("_", " ", $recurrance))));
if (is_array($opt_schedules = get_option('wprobot_schedules'))) {
if (!array_key_exists($recurrance, $opt_schedules)) {
update_option('wprobot_schedules', array_merge($schedule, $opt_schedules));
} else {
return $recurrance;
}
} else {
add_option('wprobot_schedules', $schedule);
}
return $recurrance;
}
开发者ID:haizrul,项目名称:WP-Mizon,代码行数:29,代码来源:func.php
示例5: getDrops
public function getDrops(Item $item)
{
if ($item->isPickaxe() >= Tool::TIER_IRON) {
return [[Item::REDSTONE_DUST, 0, mt_rand(4, 5)]];
}
return [];
}
开发者ID:robozeri,项目名称:Yuriko-MP,代码行数:7,代码来源:GlowingRedstoneOre.php
示例6: kill
public function kill()
{
parent::kill();
if ($this->getLevel()->getServer()->expEnabled) {
$this->getLevel()->addExperienceOrb($this->add(0, 1, 0), mt_rand(1, 3));
}
}
开发者ID:1455931078,项目名称:Genisys,代码行数:7,代码来源:Wolf.php
示例7: testRandom
/**
* @runInSeparateProcess
*/
public function testRandom()
{
$this->assertEquals(16, strlen(Str::random()));
$someInteger = mt_rand(1, 5);
$this->assertEquals($someInteger, strlen(Str::random($someInteger)));
$this->assertInternalType('string', Str::random());
}
开发者ID:chromabits,项目名称:nucleus,代码行数:10,代码来源:StrTest.php
示例8: index
function index()
{
$this->template->set('title', $this->language->get('heading_title'));
if ($this->request->isPost() && $this->validate()) {
$this->modelCategorySlider->delete_categoryslider();
$this->modelCategorySlider->update_categoryslider();
$this->session->set('message', $this->language->get('text_message'));
$this->response->redirect($this->url->ssl('extension', FALSE, array('type' => 'module')));
}
$view = $this->locator->create('template');
$view->set('heading_title', $this->language->get('heading_title'));
$view->set('heading_module', $this->language->get('heading_module'));
$view->set('heading_description', $this->language->get('heading_description'));
$view->set('text_enabled', $this->language->get('text_enabled'));
$view->set('text_disabled', $this->language->get('text_disabled'));
$view->set('entry_status', $this->language->get('entry_status'));
$view->set('text_image', $this->language->get('text_image'));
$view->set('entry_height', $this->language->get('entry_height'));
$view->set('entry_width', $this->language->get('entry_width'));
$view->set('button_list', $this->language->get('button_list'));
$view->set('button_insert', $this->language->get('button_insert'));
$view->set('button_update', $this->language->get('button_update'));
$view->set('button_delete', $this->language->get('button_delete'));
$view->set('button_save', $this->language->get('button_save'));
$view->set('button_cancel', $this->language->get('button_cancel'));
$view->set('button_print', $this->language->get('button_print'));
$view->set('tab_general', $this->language->get('tab_general'));
$view->set('error', @$this->error['message']);
$view->set('action', $this->url->ssl('module_extra_categoryslider'));
$view->set('list', $this->url->ssl('extension', FALSE, array('type' => 'module')));
$view->set('cancel', $this->url->ssl('extension', FALSE, array('type' => 'module')));
$this->session->set('cdx', md5(mt_rand()));
$view->set('cdx', $this->session->get('cdx'));
$this->session->set('validation', md5(time()));
$view->set('validation', $this->session->get('validation'));
if (!$this->request->isPost()) {
$results = $this->modelCategorySlider->get_categoryslider();
foreach ($results as $result) {
$setting_info[$result['type']][$result['key']] = $result['value'];
}
}
if ($this->request->has('catalog_categoryslider_status', 'post')) {
$view->set('catalog_categoryslider_status', $this->request->gethtml('catalog_categoryslider_status', 'post'));
} else {
$view->set('catalog_categoryslider_status', @$setting_info['catalog']['categoryslider_status']);
}
if ($this->request->has('catalog_categoryslider_image_width', 'post')) {
$view->set('catalog_categoryslider_image_width', $this->request->gethtml('catalog_categoryslider_image_width', 'post'));
} else {
$view->set('catalog_categoryslider_image_width', @$setting_info['catalog']['categoryslider_image_width']);
}
if ($this->request->has('catalog_categoryslider_image_height', 'post')) {
$view->set('catalog_categoryslider_image_height', $this->request->gethtml('catalog_categoryslider_image_height', 'post'));
} else {
$view->set('catalog_categoryslider_image_height', @$setting_info['catalog']['categoryslider_image_height']);
}
$this->template->set('content', $view->fetch('content/module_extra_categoryslider.tpl'));
$this->template->set($this->module->fetch());
$this->response->set($this->template->fetch('layout.tpl'));
}
开发者ID:digitaldevelopers,项目名称:alegrocart,代码行数:60,代码来源:module_extra_categoryslider.php
示例9: loginBegin
/**
* begin login step
*
* simply call Facebook::require_login().
*/
function loginBegin()
{
$parameters = array("scope" => $this->scope, "redirect_uri" => $this->endpoint, "display" => "page");
$optionals = array("scope", "redirect_uri", "display", "auth_type");
foreach ($optionals as $parameter) {
if (isset($this->config[$parameter]) && !empty($this->config[$parameter])) {
$parameters[$parameter] = $this->config[$parameter];
//If the auth_type parameter is used, we need to generate a nonce and include it as a parameter
if ($parameter == "auth_type") {
$nonce = md5(uniqid(mt_rand(), true));
$parameters['auth_nonce'] = $nonce;
Hybrid_Auth::storage()->set('fb_auth_nonce', $nonce);
}
}
}
if (isset($this->config['force']) && $this->config['force'] === true) {
$parameters['auth_type'] = 'reauthenticate';
$parameters['auth_nonce'] = md5(uniqid(mt_rand(), true));
Hybrid_Auth::storage()->set('fb_auth_nonce', $parameters['auth_nonce']);
}
// get the login url
$url = $this->api->getLoginUrl($parameters);
// redirect to facebook
Hybrid_Auth::redirect($url);
}
开发者ID:FaddliLWibowo,项目名称:Social-Codeigniter,代码行数:30,代码来源:Facebook.php
示例10: randomString
public function randomString($length = 10, $chars = '', $type = array())
{
$alphaSmall = 'abcdefghijklmnopqrstuvwxyz';
$alphaBig = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$num = '0123456789';
$othr = '`~!@#$%^&*()/*-+_=[{}]|;:",<>.\\/?' . "'";
$characters = "";
$string = '';
isset($type['alphaSmall']) ? $type['alphaSmall'] : ($type['alphaSmall'] = true);
isset($type['alphaBig']) ? $type['alphaBig'] : ($type['alphaBig'] = true);
isset($type['num']) ? $type['num'] : ($type['num'] = true);
isset($type['othr']) ? $type['othr'] : ($type['othr'] = false);
isset($type['duplicate']) ? $type['duplicate'] : ($type['duplicate'] = true);
if (strlen(trim($chars)) == 0) {
$type['alphaSmall'] ? $characters .= $alphaSmall : ($characters = $characters);
$type['alphaBig'] ? $characters .= $alphaBig : ($characters = $characters);
$type['num'] ? $characters .= $num : ($characters = $characters);
$type['othr'] ? $characters .= $othr : ($characters = $characters);
} else {
$characters = str_replace(' ', '', $chars);
}
if ($type['duplicate']) {
for (; $length > 0 && strlen($characters) > 0; $length--) {
$ctr = mt_rand(0, strlen($characters) - 1);
$string .= $characters[$ctr];
}
} else {
$string = substr(str_shuffle($characters), 0, $length);
}
return $string;
}
开发者ID:sintret,项目名称:yii2-basic-sintret,代码行数:31,代码来源:Util.php
示例11: dateTimeBetween
/**
* Get a DateTime object based on a random date between two given dates.
* Accepts date strings that can be recognized by strtotime().
*
* @param string $startDate Defaults to 30 years ago
* @param string $endDate Defaults to "now"
* @example DateTime('1999-02-02 11:42:52')
* @return \DateTime
*/
public static function dateTimeBetween($startDate = "-30 years", $endDate = "now")
{
$startTimestamp = strtotime($startDate);
$endTimestamp = strtotime($endDate);
$timestamp = mt_rand($startTimestamp, $endTimestamp);
return new \DateTime('@' . $timestamp);
}
开发者ID:nbremont,项目名称:Faker,代码行数:16,代码来源:DateTime.php
示例12: getCode
function getCode($num, $w, $h)
{
// 去掉了 0 1 O l 等
$str = "23456789abcdefghijkmnpqrstuvwxyz";
$code = '';
for ($i = 0; $i < $num; $i++) {
$code .= $str[mt_rand(0, strlen($str) - 1)];
}
//将生成的验证码写入session,备验证页面使用
$_SESSION["my_checkcode"] = $code;
//创建图片,定义颜色值
Header("Content-type: image/PNG");
$im = imagecreate($w, $h);
$black = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
$gray = imagecolorallocate($im, 118, 151, 199);
$bgcolor = imagecolorallocate($im, 235, 236, 237);
//画背景
imagefilledrectangle($im, 0, 0, $w, $h, $bgcolor);
//画边框
imagerectangle($im, 0, 0, $w - 1, $h - 1, $gray);
//imagefill($im, 0, 0, $bgcolor);
//在画布上随机生成大量点,起干扰作用;
for ($i = 0; $i < 80; $i++) {
imagesetpixel($im, rand(0, $w), rand(0, $h), $black);
}
//将字符随机显示在画布上,字符的水平间距和位置都按一定波动范围随机生成
$strx = rand(5, 10);
for ($i = 0; $i < $num; $i++) {
$strpos = rand(1, 6);
imagestring($im, 20, $strx, $strpos, substr($code, $i, 1), $black);
$strx += $w / 5;
}
imagepng($im);
imagedestroy($im);
}
开发者ID:hanpc,项目名称:chushen,代码行数:35,代码来源:code_char.php
示例13: save_sheet
function save_sheet($xls_obj, $dirTemp, $titre)
{
// Nom de l'onglet courant
$xls_obj->getActiveSheet()->setTitle("{$titre}");
// if(isset($_POST['date1']) && $_POST['date1'] && isset($_POST['date2']) && $_POST['date2']){
// $d1 = $_POST['date1'];
// $d2 = $_POST['date2'];
// $d1f = preg_replace("/(\d{2})\/(\d{2})\/(\d{4})/","$3$2$1",$d1);
// $d2f = preg_replace("/(\d{2})\/(\d{2})\/(\d{4})/","$3$2$1",$d2);
// $filename= "$dirTemp" . "$titre$d1f".'_'. "$d2f.xlsx";
// }else{
// $filename= "$dirTemp" . mt_rand(1,100000).'.xlsx';
// }
$filename = "{$dirTemp}" . mt_rand(1, 100000) . '.xlsx';
$objWriter = PHPExcel_IOFactory::createWriter($xls_obj, 'Excel2007');
$objWriter->save($filename);
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/force-download');
header('Content-Type: application/octet-stream');
header('Content-Type: application/download');
header("Content-Disposition: attachment;filename={$filename}");
header('Content-Transfer-Encoding: binary');
$objWriter->save('php://output');
unlink($filename);
}
开发者ID:anisinfo,项目名称:osi,代码行数:27,代码来源:testf.php
示例14: prepareRequest
/**
* prepare a json rpc request array
*
* @param $method
* @param array $params
* @return array
*/
public function prepareRequest($method, array $params = [])
{
$request = ['jsonrpc' => '2.0', 'method' => $method, 'id' => mt_rand()];
$request['params'] = $params ? $params : [];
/*$request['params'] = array_merge($request['params'], $this->params);*/
return $request;
}
开发者ID:Balamir,项目名称:randomorg,代码行数:14,代码来源:Client.php
示例15: generateFormkey
/**
* Generate the form key based on IP address
*
* @return string md5sum of IP address + unique number
*/
private function generateFormkey()
{
$ip = $_SERVER['REMOTE_ADDR'];
// mt_rand() is better than rand()
$uniqid = uniqid(mt_rand(), true);
return md5($ip . $uniqid);
}
开发者ID:boots7458,项目名称:elabftw,代码行数:12,代码来源:FormKey.php
示例16: buildSecFile
/**
* Build a secured file with token name
*
* @param string $reqkey The reference key
*
* @return string The secure key
*/
function buildSecFile($reqkey)
{
$CI =& get_instance();
$skey = mt_rand();
$dir = $CI->config->item('token_dir');
$file = $skey . '.tok';
//make the file with the reqkey value in it
file_put_contents($dir . '/' . $file, $reqkey);
//do some cleanup - find ones older then the threshold and remove
$rm = $CI->config->item('token_rm');
//this is in minutes
if (is_dir($dir)) {
if (($h = opendir($dir)) !== false) {
while (($file = readdir($h)) !== false) {
if (!in_array($file, array('.', '..'))) {
$p = $dir . '/' . $file;
if (filemtime($p) < time() - $rm * 60) {
unlink($p);
}
}
}
}
}
return $skey;
}
开发者ID:Bittarman,项目名称:joind.in,代码行数:32,代码来源:reqkey_helper.php
示例17: __construct
public function __construct($startTime, $endTime) {
$this->id = mt_rand (10000, 99999);
$this->startTime = $startTime;
$this->endTime = $endTime;
$this->monthArray = array(
'01' => "Janvier",
'02' => "Février",
'03' => "Mars",
'04' => "Avril",
'05' => "Mai",
'06' => "Juin",
'07' => "Juillet",
'08' => "Août",
'09' => "Septembre",
'10' => "Octobre",
'11' => "Novembre",
'12' => "Décembre");
$this->dayArray = array(
'0' => "Dimanche",
'1' => "Lundi",
'2' => "Mardi",
'3' => "Mercredi",
'4' => "Jeudi",
'5' => "Vendredi",
'6' => "Samedi");
}
开发者ID:amirdine,项目名称:academic-projects,代码行数:29,代码来源:TimeSlot.inc.php
示例18: execute
function execute( $par ) {
$this->setHeaders();
$this->outputHeader();
// Purge expired entries on one in every 10 queries
if ( !mt_rand( 0, 10 ) ) {
Title::purgeExpiredRestrictions();
}
$request = $this->getRequest();
$type = $request->getVal( $this->IdType );
$level = $request->getVal( $this->IdLevel );
$sizetype = $request->getVal( 'sizetype' );
$size = $request->getIntOrNull( 'size' );
$NS = $request->getIntOrNull( 'namespace' );
$pager = new ProtectedTitlesPager( $this, array(), $type, $level, $NS, $sizetype, $size );
$this->getOutput()->addHTML( $this->showOptions( $NS, $type, $level ) );
if ( $pager->getNumRows() ) {
$this->getOutput()->addHTML(
$pager->getNavigationBar() .
'<ul>' . $pager->getBody() . '</ul>' .
$pager->getNavigationBar()
);
} else {
$this->getOutput()->addWikiMsg( 'protectedtitlesempty' );
}
}
开发者ID:nahoj,项目名称:mediawiki_ynh,代码行数:30,代码来源:SpecialProtectedtitles.php
示例19: getName
public function getName($type = 1)
{
$name = '';
switch ($type) {
case 1:
// 2字
$name = $this->getXing() . $this->getMing();
break;
case 2:
// 随机2、3个字
$name = $this->getXing() . $this->getMing();
if (mt_rand(0, 100) > 50) {
$name .= $this->getMing();
}
break;
case 3:
// 只取姓
$name = $this->getXing();
break;
case 4:
// 只取名
$name = $this->getMing();
break;
case 0:
default:
// 默认情况 1姓+2名
$name = $this->getXing() . $this->getMing() . $this->getMing();
}
return $name;
}
开发者ID:xzjs,项目名称:PXPark,代码行数:30,代码来源:RandName.class.php
示例20: CaptchaSecurityImages
function CaptchaSecurityImages($width = '120', $height = '40', $characters = '6')
{
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.5;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 20, 20, 20);
$text_color = imagecolorallocate($image, 230, 197, 89);
$noise_color = imagecolorallocate($image, 0, 0, 0);
/* generate random dots in background */
for ($i = 0; $i < $width * $height / 3; $i++) {
imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
}
/* generate random lines in background */
/*for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}*/
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4]) / 2;
$y = ($height - $textbox[5]) / 2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
/* output captcha image to browser */
header('Content-Type: image/jpeg');
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}
开发者ID:jassimtalat,项目名称:KMRD_2010,代码行数:29,代码来源:CaptchaSecurityImages.php
注:本文中的mt_rand函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论