• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP mt_getrandmax函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中mt_getrandmax函数的典型用法代码示例。如果您正苦于以下问题:PHP mt_getrandmax函数的具体用法?PHP mt_getrandmax怎么用?PHP mt_getrandmax使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了mt_getrandmax函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: rrt

 function rrt($rate)
 {
     $min = 0;
     $max = 1;
     $R = 0.75;
     $count = 0;
     $arraylist = array();
     $fail_rate = $rate;
     $fail_start = ($min + mt_rand() / mt_getrandmax() * ($max - $min)) * (1 - $fail_rate);
     $p = $min + mt_rand() / mt_getrandmax() * ($max - $min);
     while (!($p > $fail_start && $p < $fail_start + $fail_rate)) {
         $count++;
         array_push($arraylist, $p);
         $flag = true;
         while ($flag) {
             $flag = false;
             $p = $min + mt_rand() / mt_getrandmax() * ($max - $min);
             $r = $R / (2 * count($arraylist));
             for ($i = 0; $i < count($arraylist); $i++) {
                 if ($p > $arraylist[$i] - $r && $p < $arraylist[$i] + $r) {
                     $flag = true;
                 }
             }
         }
     }
     return $count;
 }
开发者ID:xilovesyu,项目名称:xijiaxiangwexin,代码行数:27,代码来源:Service.php


示例2: get_token

 public function get_token()
 {
     // Create a token
     $token = hash('sha512', mt_rand(0, mt_getrandmax()) . microtime(TRUE));
     $_SESSION['token'] = $token;
     return $token;
 }
开发者ID:raakesh,项目名称:php-security-pitfalls,代码行数:7,代码来源:csrf.php


示例3: send

 public static function send($data, $sampleRate = 1)
 {
     $config = Config::getInstance();
     if (!$config->isEnabled("statsd")) {
         return;
     }
     // sampling
     $sampledData = array();
     if ($sampleRate < 1) {
         foreach ($data as $stat => $value) {
             if (mt_rand() / mt_getrandmax() <= $sampleRate) {
                 $sampledData[$stat] = "{$value}|@{$sampleRate}";
             }
         }
     } else {
         $sampledData = $data;
     }
     if (empty($sampledData)) {
         return;
     }
     // Wrap this in a try/catch - failures in any of this should be silently ignored
     try {
         $host = $config->getConfig("statsd.host");
         $port = $config->getConfig("statsd.port");
         $fp = fsockopen("udp://{$host}", $port, $errno, $errstr);
         if (!$fp) {
             return;
         }
         foreach ($sampledData as $stat => $value) {
             fwrite($fp, "{$stat}:{$value}");
         }
         fclose($fp);
     } catch (Exception $e) {
     }
 }
开发者ID:nremond,项目名称:statsd,代码行数:35,代码来源:php-example.php


示例4: getRandomNumber

 /**
  * Return a random number in the specified range
  *
  * @param $min [optional]
  * @param $max [optional]
  * @return int A random integer value between min (or 0) and max
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public static function getRandomNumber($min = 0, $max = null)
 {
     if (null === $max) {
         $max = mt_getrandmax();
     }
     $range = $max - $min + 1;
     $offset = 0;
     if (function_exists('openssl_random_pseudo_bytes')) {
         // use openssl lib if it is installed
         $bytes = openssl_random_pseudo_bytes(PHP_INT_SIZE);
         $hex = bin2hex($bytes);
         // hex() doubles the length of the string
         $offset = abs(hexdec($hex) % $range);
         // random integer from 0 to $range
     } elseif ($fp = @fopen('/dev/urandom', 'rb')) {
         // attempt to use /dev/urandom if it exists but openssl isn't available
         $bytes = @fread($fp, PHP_INT_SIZE);
         $hex = bin2hex($bytes);
         // hex() doubles the length of the string
         $offset = abs(hexdec($hex) % $range);
         // random integer from 0 to $range
         fclose($fp);
     } else {
         throw new \Magento\Framework\Exception\LocalizedException(new \Magento\Framework\Phrase("Please make sure you have 'openssl' extension installed"));
     }
     return $min + $offset;
     // random integer from $min to $max
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:36,代码来源:Random.php


示例5: __construct

 public function __construct($dir)
 {
     if (self::$useDirectories === NULL) {
         // checks whether directory is writable
         $uniq = uniqid('_', TRUE);
         umask(00);
         if (!@mkdir("{$dir}/{$uniq}", 0777)) {
             // @ - is escalated to exception
             throw new InvalidStateException("Unable to write to directory '{$dir}'. Make this directory writable.");
         }
         // tests subdirectory mode
         self::$useDirectories = !ini_get('safe_mode');
         if (!self::$useDirectories && @file_put_contents("{$dir}/{$uniq}/_", '') !== FALSE) {
             // @ - error is expected
             self::$useDirectories = TRUE;
             unlink("{$dir}/{$uniq}/_");
         }
         rmdir("{$dir}/{$uniq}");
     }
     $this->dir = $dir;
     $this->useDirs = (bool) self::$useDirectories;
     if (mt_rand() / mt_getrandmax() < self::$gcProbability) {
         $this->clean(array());
     }
 }
开发者ID:jaroslavlibal,项目名称:MDW,代码行数:25,代码来源:FileStorage.php


示例6: up

 public function up()
 {
     //we'll need some places where the events can take place
     $locations = array('Rīga', 'Valmiera', 'Ventspils');
     foreach ($locations as $location) {
         $loc = \Model_Orm_Location::forge();
         $loc->title = $location;
         $loc->save();
     }
     //and let's create at least one event as well
     $demo_event = \Model_Orm_Event::forge();
     $demo_event->title = "Notikums pēc nedēļas";
     $demo_event->description = "Kaut kas, kam jānotiek nedēļu vēlāk nekā šī skripta izpilde.";
     $startdate = \Fuel\Core\Date::forge(time() + 7 * 24 * 60 * 60);
     $demo_event->start = $startdate->format('mysql', false);
     //'2013-11-27 07:00:00';
     $demo_event->location_id = 1;
     //pieņemsim, ka Rīgā;
     $demo_event->save();
     //the event shouldn't be empty - some agenda items
     $agenda_items = array('Notikuma pats, pats sākums', 'Kaut kad drusku vēlāk', 'Vēl mazliet vēlāk', 'Un nu jau arī beigas');
     foreach ($agenda_items as $agenda_item) {
         $demo_agenda = \Model_Orm_Agenda::forge();
         $demo_agenda->title = $agenda_item;
         $demo_agenda->event = $demo_event;
         $demo_agenda->save();
     }
     //we also need some users. at least two.
     \Auth::instance()->create_user("[email protected]", "fuel_dev", "[email protected]", 100, array("verified" => true, "verification_key" => md5(mt_rand(0, mt_getrandmax()))));
     \Auth::instance()->create_user("[email protected]", "fuel_dev", "[email protected]", 1, array("verified" => true, "verification_key" => md5(mt_rand(0, mt_getrandmax()))));
 }
开发者ID:beingsane,项目名称:TTII_2012,代码行数:31,代码来源:002_demo_data.php


示例7: getSiftScore

function getSiftScore($userid)
{
    if (!SHIFT_SCIENCE_KEY) {
        return mt_rand() / mt_getrandmax();
    }
    // create curl resource
    $ch = curl_init();
    $api_key = SHIFT_SCIENCE_KEY;
    // set url
    curl_setopt($ch, CURLOPT_URL, "https://api.siftscience.com/v203/score/{$userid}/?api_key={$api_key}");
    //return the transfer as a string
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    // $output contains the output string
    $output = curl_exec($ch);
    // close curl resource to free up system resources
    curl_close($ch);
    $sift_data = json_decode($output);
    if ($sift_data->status != 0) {
        $sift_data->score = null;
        if ($sift_data->error_message != 'Specified user_id has no scorable events') {
            throw new Exception($sift_data->error_message);
        }
    }
    $sift_score = $sift_data->score;
    return $sift_score;
}
开发者ID:narvee,项目名称:nripl.org,代码行数:26,代码来源:get_sift_scores.php


示例8: send

 public static function send($data, $sampleRate = 1)
 {
     if (!self::$enabled) {
         return;
     }
     // sampling
     $sampledData = array();
     if ($sampleRate < 1) {
         foreach ($data as $stat => $value) {
             if (mt_rand() / mt_getrandmax() <= $sampleRate) {
                 $sampledData[$stat] = "{$value}|@{$sampleRate}";
             }
         }
     } else {
         $sampledData = $data;
     }
     if (empty($sampledData)) {
         return;
     }
     // Wrap this in a try/catch - failures in any of this should be silently ignored
     try {
         $host = 'statsd.p.rayku.com';
         $port = 8125;
         $fp = fsockopen("udp://{$host}", $port, $errno, $errstr);
         if (!$fp) {
             return;
         }
         foreach ($sampledData as $stat => $value) {
             fwrite($fp, "{$stat}:{$value}");
         }
         fclose($fp);
     } catch (Exception $e) {
     }
 }
开发者ID:rayku,项目名称:rayku,代码行数:34,代码来源:StatsD.class.php


示例9: getRandom

 private function getRandom($min, $max)
 {
     $factor = (double) mt_rand() / (double) mt_getrandmax();
     $random = mt_rand($min, $max) * $factor;
     $result = $random + $min > $max ? $random : $random + $min;
     return round($result, 2);
 }
开发者ID:junjinZ,项目名称:wealthbot,代码行数:7,代码来源:LoadSecurityPriceData.php


示例10: autologin

 function autologin()
 {
     if ($_COOKIE["autologin"]) {
         $data = unserialize($_COOKIE["autologin"]);
         if (isset($data['key']) and isset($data['user_id'])) {
             $cookiedata = $this->select_cookie($data['user_id'], $data['key']);
             if (!is_null($cookiedata)) {
                 $user_data = serialize(array('user_id' => $cookiedata[0]["id"], 'username' => $cookiedata[0]["username"], 'email' => $cookiedata[0]["email"], 'status' => $cookiedata[0]["activated"] == 1 ? '1' : '0'));
                 $ip = getenv("REMOTE_ADDR");
                 $sessid = '';
                 while (strlen($sessid) < 32) {
                     $sessid .= mt_rand(0, mt_getrandmax());
                 }
                 $session_id = md5(uniqid($sessid, TRUE));
                 $user_agent = $_SERVER["HTTP_USER_AGENT"];
                 $now = time();
                 $time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now));
                 $aryCookie = unserialize($_COOKIE['ci_session']);
                 $this->clearsession($aryCookie['session_id']);
                 setcookie('ci_session', '', time() - 1, '/');
                 $sessiondata = $this->creatsession($session_id, $ip, $user_agent, $time, $user_data);
                 $ci_session_data = serialize(array('session_id' => $session_id, 'ip_address' => $_SERVER['REMOTE_ADDR'], 'user_agent' => $user_agent, 'last_activity' => $time));
                 setcookie('autologin', serialize(array('user_id' => $data['user_id'], 'key' => $data['key'])), time() + 60 * 60 * 24 * 31 * 2, '/');
                 //setcookie('ci_session',$ci_session_data,0,'/');
                 //print_r($_COOKIE['ci_session']);
                 $this->update_user($data['user_id']);
                 return $session_id;
             }
         }
     }
     return FALSE;
 }
开发者ID:neruchan,项目名称:cinderella.tiary.jp,代码行数:32,代码来源:myautologin.php


示例11: init

function init()
{
    global $gcInternal, $gcProbability;
    if ($gcInternal === true && ($gcProbability === 1.0 || mt_rand() / mt_getrandmax() < $gcProbability)) {
        runGc();
    }
}
开发者ID:dg-wfk,项目名称:dl,代码行数:7,代码来源:admfuncs.php


示例12: logisticWithoutKey

 /**
  * 无key方式访问
  * @return $this
  */
 public function logisticWithoutKey()
 {
     $temp = mt_rand() / mt_getrandmax();
     $url = 'http://www.kuaidi100.com/query?type=' . $this->company_code . '&postid=' . $this->logistic_num . '&id=1&valicode=&temp=' . $temp;
     //初始化curl
     $ch = curl_init();
     //设置超时
     curl_setopt($ch, CURLOPT_TIMEOUT, 60);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
     curl_setopt($ch, CURLOPT_HEADER, FALSE);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/" . self::randomIp() . " Safari/536.11");
     $res = curl_exec($ch);
     curl_close($ch);
     $this->data = json_decode($res, true);
     if (is_array($this->data) && array_key_exists('status', $this->data)) {
         $this->status = $this->data['status'];
     }
     if (is_array($this->data) && array_key_exists('message', $this->data)) {
         $this->message = $this->data['message'];
     }
     if (is_array($this->data) && array_key_exists('state', $this->data)) {
         $this->state = $this->data['state'];
     }
     return $this;
 }
开发者ID:jiangxianli,项目名称:kuaidi,代码行数:32,代码来源:Kuaidi.php


示例13: getRandomNumber

 /**
  * Return a random number in the specified range
  *
  * @param $min [optional]
  * @param $max [optional]
  * @return int A random integer value between min (or 0) and max
  */
 public static function getRandomNumber($min = 0, $max = null)
 {
     if (null === $max) {
         $max = mt_getrandmax();
     }
     $range = $max - $min + 1;
     $offset = 0;
     if (function_exists('openssl_random_pseudo_bytes')) {
         // use openssl lib if it is installed
         $bytes = openssl_random_pseudo_bytes(PHP_INT_SIZE);
         $hex = bin2hex($bytes);
         // hex() doubles the length of the string
         $offset = abs(hexdec($hex) % $range);
         // random integer from 0 to $range
     } elseif ($fp = @fopen('/dev/urandom', 'rb')) {
         // attempt to use /dev/urandom if it exists but openssl isn't available
         $bytes = @fread($fp, PHP_INT_SIZE);
         $hex = bin2hex($bytes);
         // hex() doubles the length of the string
         $offset = abs(hexdec($hex) % $range);
         // random integer from 0 to $range
         fclose($fp);
     } else {
         // fallback to mt_rand() if all else fails
         mt_srand(mt_rand() + 100000000 * microtime() % PHP_INT_MAX);
         return mt_rand($min, $max);
         // random integer from $min to $max
     }
     return $min + $offset;
     // random integer from $min to $max
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:38,代码来源:Random.php


示例14: array_random

 function array_random(array $array, $num = 1)
 {
     return array_random_callback($array, function () {
         $ramdom = ramdom_int();
         return $ramdom !== false ? floatval($ramdom) / floatval(PHP_INT_MAX + 1.0) : floatval(mt_rand()) / floatval(mt_getrandmax() + 1.0);
     }, $num);
 }
开发者ID:algo13,项目名称:php-random,代码行数:7,代码来源:array_random.inc.php


示例15: load

 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $faker = $this->getFaker();
     $fly1 = new Fly();
     $fly1->setName('chateau des vaux');
     $fly1->setLatitude('48');
     $fly1->setLongitude('1.0');
     $fly1->setDescription('magnifique chateau de la region ');
     $fly1->setCategory($faker->randomElement($fly1->getCategoryValues()));
     $manager->persist($fly1);
     $manager->flush();
     $lon_min = -1.0522795;
     $lon_max = 6.7260408;
     $lat_min = 42.4838724;
     $lat_max = 49.66374;
     foreach (range(1, 20) as $id) {
         $fly = new Fly();
         $fly->setName($faker->userName);
         $fly->setDescription($faker->realText(250));
         $fly->setLatitude(mt_rand() / mt_getrandmax() * ($lat_max - $lat_min) + $lat_min);
         $fly->setLongitude(mt_rand() / mt_getrandmax() * ($lon_max - $lon_min) + $lon_min);
         $fly->setCategory($faker->randomElement($fly1->getCategoryValues()));
         $manager->persist($fly);
     }
     $manager->flush();
 }
开发者ID:sev28,项目名称:flyaround_s2,代码行数:29,代码来源:LoadFlyData.php


示例16: send

 public static function send($data, $sampleRate = 1)
 {
     if (empty(Z_CONFIG::$STATSD_ENABLED)) {
         return;
     }
     // sampling
     $sampledData = array();
     if ($sampleRate < 1) {
         foreach ($data as $stat => $value) {
             if (mt_rand() / mt_getrandmax() <= $sampleRate) {
                 $sampledData[$stat] = "{$value}|@{$sampleRate}";
             }
         }
     } else {
         $sampledData = $data;
     }
     if (empty($sampledData)) {
         return;
     }
     // Wrap this in a try/catch - failures in any of this should be silently ignored
     try {
         $host = Z_CONFIG::$STATSD_HOST;
         $port = Z_CONFIG::$STATSD_PORT;
         $fp = fsockopen("udp://{$host}", $port, $errno, $errstr);
         if (!$fp) {
             return;
         }
         foreach ($sampledData as $stat => $value) {
             fwrite($fp, Z_CONFIG::$STATSD_PREFIX . "{$stat}:{$value}");
         }
         fclose($fp);
     } catch (Exception $e) {
     }
 }
开发者ID:selenus,项目名称:dataserver,代码行数:34,代码来源:StatsD.inc.php


示例17: RequestCode

 public function RequestCode($return, $scope = [])
 {
     $state = mt_rand(0, mt_getrandmax());
     $scope = implode(',', $scope);
     $query_string = http_build_query(['state' => $state, 'scope' => $scope, 'return' => $return]);
     return (object) ['URL' => \s5\API::$OAuthBase . '/' . $this->API->Token . '?' . $query_string, 'State' => $state];
 }
开发者ID:studentrnd,项目名称:s5api,代码行数:7,代码来源:OAuth.php


示例18: auth_change_password

function auth_change_password($username, $password)
{
    $username_encoded = urlencode($username);
    $salt = hash("sha512", uniqid(mt_rand(1, mt_getrandmax()), true));
    $password_encoded = hash("sha512", $password . $salt);
    mysql_query("UPDATE users SET salt = '{$salt}', password = '{$password_encoded}' WHERE username = '{$username_encoded}'") or die(mysql_error());
}
开发者ID:KMSUJ,项目名称:archive,代码行数:7,代码来源:auth.inc.php


示例19: change_password

function change_password($dbh1, $table_prefix1)
{
    // Create salted password (Careful not to over season)
    if (strcmp($_POST['new_pass_enc'], $_POST['new_pass_enc2']) !== 0) {
        $array['status'] = 'error';
        $array['message'] = "Heslá sa nezhodujú";
    } else {
        $random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
        $password1 = hash('sha512', $_POST['new_pass_enc'] . $random_salt);
        if ($stmt = $dbh1->prepare("SELECT user_id FROM " . $table_prefix1 . "_password_reset WHERE hash = ? LIMIT 1")) {
            $stmt->bindParam(1, $_POST['string']);
            $stmt->execute();
            $stmt->result = $stmt->fetch();
            if ($insert_stmt = $dbh1->prepare("UPDATE " . $table_prefix1 . "_users SET password=?, salt=? WHERE id=?")) {
                $insert_stmt->bindParam(1, $password1);
                $insert_stmt->bindParam(2, $random_salt);
                $insert_stmt->bindParam(3, $stmt->result['user_id']);
                $insert_stmt->execute();
                $array['status'] = 'success';
                $array['message'] = "Heslo bolo úspešne zmenené. Budete presmerovany na prihlasovaciu stranku.";
                if ($select_stmt = $dbh1->prepare("DELETE FROM " . $table_prefix1 . "_password_reset WHERE hash=?")) {
                    $select_stmt->bindValue(1, $_POST['string']);
                    $select_stmt->execute();
                }
            } else {
                $array['status'] = 'error';
                $array['message'] = "Pri ukladaní údajov sa vyskytla chyba";
            }
        } else {
            $array['status'] = 'error';
            $array['message'] = "Pri zmene hesla sa vyskytla chyba. Odkaz nie je platný";
        }
    }
    echo json_encode($array);
}
开发者ID:centaurustech,项目名称:Funduj,代码行数:35,代码来源:change_password.php


示例20: connectToUser

 public function connectToUser($me, $you)
 {
     foreach ($this->conns as $c) {
         if ($c['two'] == $me->id && $c['one'] == $you->id && time() < $c['time'] + 30 && $c['active'] == 1) {
             $game_id = sha1(mt_rand(0, mt_getrandmax()) . 'fniyhksmi53?');
             $turn = mt_rand(0, 1) == 1 ? $me->id : $you->id;
             $game['id'] = $game_id;
             $game['turn'] = $turn;
             $game['moves'] = 0;
             $game['winner'] = 'PENDING';
             $game['one'] = $me->id;
             $game['two'] = $you->id;
             $arr = array();
             for ($r = 0; $r < 7; $r++) {
                 for ($c = 0; $c < 7; $c++) {
                     $arr[$r][$c] = -1;
                 }
             }
             $game['grid'] = $arr;
             $this->games[$game_id] = $game;
             $c['active'] = 0;
             return $game;
         }
     }
     $mycon['one'] = $me->id;
     $mycon['two'] = $you->id;
     $mycon['time'] = time();
     $mycon['active'] = 1;
     $this->conns[] = $mycon;
     return -1;
 }
开发者ID:kperson,项目名称:Connect4-Websockets,代码行数:31,代码来源:socketserver.php



注:本文中的mt_getrandmax函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP mt_rand函数代码示例发布时间:2022-05-15
下一篇:
PHP mt函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap