当前位置: 首页>>代码示例>>PHP>>正文


PHP mt_srand函数代码示例

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


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

示例1: 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

示例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: son

 function son()
 {
     $son = "^°!\"§\$%&/()=?`²³{[]}\\´@+*~#'-_.:,;<>|µ";
     mt_srand((double) microtime() * 10000);
     $return = $son[rand(0, strlen($son))];
     return $return;
 }
开发者ID:BackupTheBerlios,项目名称:swora,代码行数:7,代码来源:class.rand.php

示例4: getverifycode

function getverifycode()
{
    $length = 6;
    PHP_VERSION < '4.2.0' && mt_srand((double) microtime() * 1000000);
    $hash = sprintf('%0' . $length . 'd', mt_rand(0, pow(10, $length) - 1));
    return $hash;
}
开发者ID:nanhuacrab,项目名称:ecshop,代码行数:7,代码来源:lib_sms.php

示例5: guid

 function guid()
 {
     mt_srand((double) microtime() * 10000);
     $charid = strtoupper(md5(uniqid(rand(), true)));
     $guid = substr($charid, 0, 8) . '-' . substr($charid, 8, 4) . '-' . substr($charid, 12, 4) . '-' . substr($charid, 16, 4) . '-' . substr($charid, 20, 12);
     return $guid;
 }
开发者ID:manishkhanchandani,项目名称:mkgxy,代码行数:7,代码来源:index.php

示例6: genKey

function genKey($length, $type = null)
{
    if ($length > 0) {
        $rand_id = "";
        for ($i = 1; $i <= $length; $i++) {
            mt_srand((double) microtime() * 1000000);
            $min = 1;
            switch ($type) {
                case 'numeric':
                    $max = 10;
                    break;
                case 'alpha':
                    $min = 11;
                    $max = 62;
                    break;
                case 'alphanumeric':
                    $max = 62;
                    break;
                default:
                    $max = 72;
                    break;
            }
            $num = mt_rand($min, $max);
            $rand_id .= assign_rand_value($num);
        }
    }
    return $rand_id;
}
开发者ID:actcux,项目名称:ProyectoNotasQr,代码行数:28,代码来源:common_helper.php

示例7: setClient

 public function setClient($login, $psw, $email, $phone, $code, $firstname, $surname)
 {
     $data = array('data' => array('login' => $login, 'psw' => $psw, $email, $phone, 'SC' => $code, 'sesSC' => $_SESSION["secret_number"]), 'CID' => NULL, 'query' => NULL);
     if (intval($_SESSION["secret_number"]) < 1000) {
         mt_srand(time() + (double) microtime() * 1000000);
         $_SESSION["secret_number"] = mt_rand(1000, 9999);
     }
     if ($_SERVER["REQUEST_METHOD"] === "POST") {
         $error = 0;
         if (intval($code) !== $_SESSION["secret_number"] || intval($code) === 0) {
             $data['msg'] = 'Число з картинки введене невірно!';
         } else {
             $salt = $this->getSalt();
             $password = hash('sha256', $psw . $salt);
             $log = hash('sha256', $login);
             $data['sha256'] = $log;
             $query = "INSERT INTO `users`(`login`, `password`, `salt`, `firstname`, `surname`,  `email`, `phone`) VALUES ('{$log}','{$password}','{$salt}','{$firstname}','{$surname}','{$email}','{$phone}')";
             $data['query'] = $query;
             if (mysql_query($query)) {
                 $this->_mail($email, $login, $password);
                 $cid = mysql_insert_id();
                 $_SESSION['CID'] = $cid;
                 $data["CID"] = $cid;
             }
         }
         // оновлюємо "таємне" число
         mt_srand(time() + (double) microtime() * 1000000);
         $_SESSION["secret_number"] = mt_rand(1000, 9999);
     }
     return $data;
 }
开发者ID:szatsepa,项目名称:psiho-test,代码行数:31,代码来源:model_registration.php

示例8: doMobileDetail

 public function doMobileDetail()
 {
     global $_W, $_GPC;
     checkauth();
     $rid = intval($_GPC['rid']);
     $reply = pdo_fetch("SELECT * FROM " . tablename('shake_reply') . " WHERE rid = :rid", array(':rid' => $rid));
     if (empty($reply)) {
         message('抱歉,此活动不存在或是还未开始!', 'refresh', 'error');
     }
     $member = pdo_fetch("SELECT * FROM " . tablename('shake_member') . " WHERE rid = :rid AND openid = :openid", array(':rid' => $reply['rid'], ':openid' => $_W['member']['uid']));
     if (empty($member)) {
         $member = array('rid' => $rid, 'openid' => $_W['member']['uid'], 'createtime' => TIMESTAMP, 'shakecount' => 0, 'status' => 0);
         $maxjoin = pdo_fetchcolumn("SELECT COUNT(*) FROM " . tablename('shake_member') . " WHERE rid = '{$reply['rid']}' AND status = '1'");
         if ($maxjoin < $reply['maxjoin']) {
             mt_srand((double) microtime() * 1000000);
             $rand = mt_rand(1, 100);
             if ($rand <= $reply['joinprobability']) {
                 $member['status'] = 1;
             }
         }
         pdo_insert('shake_member', $member);
     }
     if (strexists(strtolower($_SERVER['HTTP_USER_AGENT']), 'android')) {
         $reply['speed'] = $reply['speedandroid'];
     }
     include $this->template('detail');
 }
开发者ID:eduNeusoft,项目名称:weixin,代码行数:27,代码来源:site.php

示例9: skipdays

function skipdays($days)
{
    if ($days == 1) {
        print "<td>&nbsp;</td>\n";
    } else {
        if ($days > 3 && file_exists("Quotations")) {
            mt_srand((double) microtime() * 1000000);
            $lines = file("includes/text/quotations.txt");
            $line_number = mt_rand(0, sizeof($lines) - 1);
            $quotation = htmlspecialchars($lines[$line_number]);
            $quotation = preg_replace('/^(.*)~/', '<em>$1</em><br>--', $quotation);
            $length = strlen($lines[$line_number]);
            $style = "text-align:center; color: #804000;";
            if ($length / $days > 80) {
                $style .= "font-size: xx-small;";
            } else {
                if ($length / $days > 50) {
                    $style .= "font-size: x-small;";
                } else {
                    if ($length / $days > 35) {
                        $style .= "font-size: small;";
                    }
                }
            }
            print "<td colspan={$days} style=\"{$style}\">{$quotation}</td>\n";
        } else {
            print "<td colspan={$days}>&nbsp;</td>\n";
        }
    }
}
开发者ID:CorySpitzer,项目名称:shiftcal,代码行数:30,代码来源:viewmonth.php

示例10: genToken

 static function genToken($len = 32, $md5 = true)
 {
     # Seed random number generator
     # Only needed for PHP versions prior to 4.2
     mt_srand((double) microtime() * 1000000);
     # Array of characters, adjust as desired
     $chars = array('Q', '@', '8', 'y', '%', '^', '5', 'Z', '(', 'G', '_', 'O', '`', 'S', '-', 'N', '<', 'D', '{', '}', '[', ']', 'h', ';', 'W', '.', '/', '|', ':', '1', 'E', 'L', '4', '&', '6', '7', '#', '9', 'a', 'A', 'b', 'B', '~', 'C', 'd', '>', 'e', '2', 'f', 'P', 'g', ')', '?', 'H', 'i', 'X', 'U', 'J', 'k', 'r', 'l', '3', 't', 'M', 'n', '=', 'o', '+', 'p', 'F', 'q', '!', 'K', 'R', 's', 'c', 'm', 'T', 'v', 'j', 'u', 'V', 'w', ',', 'x', 'I', '$', 'Y', 'z', '*');
     # Array indice friendly number of chars;
     $numChars = count($chars) - 1;
     $token = '';
     # Create random token at the specified length
     for ($i = 0; $i < $len; $i++) {
         $token .= $chars[mt_rand(0, $numChars)];
     }
     # Should token be run through md5?
     if ($md5) {
         # Number of 32 char chunks
         $chunks = ceil(strlen($token) / 32);
         $md5token = '';
         # Run each chunk through md5
         for ($i = 1; $i <= $chunks; $i++) {
             $md5token .= md5(substr($token, $i * 32 - 32, 32));
         }
         # Trim the token
         $token = substr($md5token, 0, $len);
     }
     return $token;
 }
开发者ID:OwnQuestion,项目名称:QuestionServer,代码行数:28,代码来源:Utility.php

示例11: getFileCache

 public static function getFileCache($location, $expire = false)
 {
     if (is_bool($expire)) {
         $expire = 60 * 30;
     }
     $hash = sha1($location);
     $cacheDir = self::$cache_url;
     $file = "{$cacheDir}{$hash}";
     if (file_exists($file)) {
         $file_content = file_get_contents($file);
         $unserialize_file = unserialize($file_content);
         $file_expire = $unserialize_file['expire'];
         if ($file_expire > time()) {
             return base64_decode($unserialize_file['content']);
         }
     }
     mt_srand();
     $randomize_user_agent = self::$user_agents[mt_rand(0, count(self::$user_agents) - 1)];
     $location = parse_url($location);
     $http = "http://{$location['host']}";
     $path = "{$location['path']}?{$location['query']}";
     $client = new Client($http);
     $request = $client->get($path);
     $request->setHeader('User-Agent', $randomize_user_agent);
     $response = $request->send();
     if (!$response->isSuccessful()) {
         return false;
     }
     $content = $response->getBody(true);
     $store = array('date' => time(), 'expire' => time() + $expire, 'content' => base64_encode($content));
     $serialize = serialize($store);
     file_put_contents($file, $serialize);
     return $content;
 }
开发者ID:robertkraig,项目名称:Craigslist-Aggregator-silex,代码行数:34,代码来源:Utils.php

示例12: b_show_rmsrv_banners

function b_show_rmsrv_banners()
{
    global $xoopsDB;
    $myts =& MyTextSanitizer::getInstance();
    $block = array();
    list($num) = $xoopsDB->fetchRow($xoopsDB->query("SELECT COUNT(*) FROM " . $xoopsDB->prefix("rmsrv_banners")));
    if ($num <= 0) {
        return;
    }
    if ($num > 1) {
        $num = $num - 1;
        mt_srand((double) microtime() * 1000000);
        $snum = mt_rand(0, $num);
    } else {
        $snum = 0;
    }
    $sql = "SELECT * FROM " . $xoopsDB->prefix("rmsrv_banners") . " LIMIT {$snum}, 1";
    $result = $xoopsDB->query($sql);
    $row = $xoopsDB->fetchArray($result);
    $rtn = array();
    include_once XOOPS_ROOT_PATH . "/modules/rmservices/include/functions.php";
    if ($row['buy']) {
        $form = FormBuy(ServiceData($row['id_srv'], "nombre"), ServiceData($row['id_srv'], "codigo"), ServiceData($row['id_srv'], "precio"), 'srv');
    }
    $rtn['id'] = $row['id_ban'];
    $rtn['img'] = str_replace('{servicio}', $row['id_srv'], $row['img']);
    $rtn['desc'] = $myts->makeTareaData4Show($row['desc']);
    $rtn['border'] = $row['showborder'];
    $rtn['ids'] = $row['id_srv'];
    $rtn['form'] = $form;
    $block['bann'][] = $rtn;
    return $block;
}
开发者ID:BackupTheBerlios,项目名称:soopa,代码行数:33,代码来源:rmsrv_banners.php

示例13: generateToken

 private function generateToken() : string
 {
     mt_srand((double) microtime() * 10000);
     $charid = strtoupper(md5(uniqid(rand(), true)));
     $retval = substr($charid, 0, 32);
     return $retval;
 }
开发者ID:wellcommerce,项目名称:wellcommerce,代码行数:7,代码来源:PaymentFactory.php

示例14: randomRatio

 /**
  * @param float $ratioMin
  * @param float $ratioMax
  * @param int $seed
  *
  * @return float
  */
 private function randomRatio($ratioMin, $ratioMax, $seed)
 {
     $precision = 100;
     mt_srand($seed);
     //so that values are same across tests
     return mt_rand($ratioMin * $precision, $ratioMax * $precision) / $precision;
 }
开发者ID:drewclauson,项目名称:TbbcMoneyBundle,代码行数:14,代码来源:StaticRatioProviderTest.php

示例15: getRandomInt

 /**
  * generates a random int
  *
  * @param int $length
  *
  * @return int
  */
 public static function getRandomInt($length = 10) : int
 {
     $time = time();
     mt_srand($time);
     $tmp = mt_rand();
     return (int) substr(number_format($tmp, 0, '', ''), 0, $length);
 }
开发者ID:chilimatic,项目名称:traits-component,代码行数:14,代码来源:RandomDataGenerator.php


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