当前位置: 首页 > news >正文

我要建立个人网站淮安专业做网站的公司

我要建立个人网站,淮安专业做网站的公司,网站认证收费,小程序定制开发话术第一种方法用mt_rand() 第二种方法#xff08;最快的#xff09; 第三种取当时时间戳 第四种打乱字符串 5 //开始创建验证码(直接用函数生成#xff0c;比较方便快捷) php mt_rand生成0~1随机小数的效果比较 第一种方法用mt_rand() function GetRandStr($length){ $s… 第一种方法用mt_rand() 第二种方法最快的 第三种取当时时间戳 第四种打乱字符串 5 //开始创建验证码(直接用函数生成比较方便快捷) php mt_rand生成0~1随机小数的效果比较 第一种方法用mt_rand() function GetRandStr($length){ $strabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789; $lenstrlen($str)-1; $randstr; for($i0;$i$length;$i){ $nummt_rand(0,$len); $randstr . $str[$num]; } return $randstr; } $numberGetRandStr(6); echo $number; 第二种方法最快的 function make_password( $length 8 ) {// 密码字符集可任意添加你需要的字符$chars array(a, b, c, d, e, f, g, h, i, j, k, l,m, n, o, p, q, r, s, t, u, v, w, x, y,z, A, B, C, D, E, F, G, H, I, J, K, L,M, N, O, P, Q, R, S, T, U, V, W, X, Y,Z, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, !, ,#, $, %, ^, , *, (, ), -, _, [, ], {, }, , , ~, , , , ,, ., ;, :, /, ?, |);// 在 $chars 中随机取 $length 个数组元素键名$keys array_rand($chars, $length); $password ;for($i 0; $i $length; $i){// 将 $length 个数组元素连接成字符串$password . $chars[$keys[$i]];}return $password; } 第三种取当时时间戳 function get_password( $length 8 ) {$str substr(md5(time()), 0, $length);//md5加密time()当前时间戳return $str; } 第四种打乱字符串 function getrandstr(){ $strABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890; $randStr str_shuffle($str);//打乱字符串 $rands substr($randStr,0,6);//substr(string,start,length);返回字符串的一部分 return $rands; } 5 //开始创建验证码(直接用函数生成比较方便快捷) $code rand(10000, 99999); php mt_rand生成0~1随机小数的效果比较 lcg_value说明 float lcg_value ( void ) lcg_value() 返回范围为 (0, 1) 的一个伪随机数。本函数组合了周期为 2^31 - 85 和 2^31 - 249 的两个同余发生器。本函数的周期等于这两个素数的乘积。 返回范围为 (0, 1) 的伪随机数。 ?php for($i0; $i5; $i){echo lcg_value().PHP_EOL; } ? 输出 0.11516515851995 0.064684551575297 0.68275174031189 0.55730746529099 0.70215008878091 两种生成0~1随机小数方法进行比较 1.执行时间比较 执行10万次基于mt_rand()与mt_getrandmax()算法的运行时间 ?php /*** 生成0~1随机小数* param Int $min* param Int $max* return Float*/ function randFloat($min0, $max1){return $min mt_rand()/mt_getrandmax() * ($max-$min); }// 获取microtime function get_microtime(){list($usec, $sec) explode( , microtime());return (float)$usec (float)$sec; }// 记录开始时间 $starttime get_microtime();// 执行10万次获取随机小数 for($i0; $i100000; $i){randFloat(); }// 记录结束时间 $endtime get_microtime();// 输出运行时间 printf(run time %f ms\r\n, ($endtime-$starttime)*1000); ? 输出run time 266.893148 ms 执行10万次lcg_value()的运行时间 ?php // 获取microtime function get_microtime(){list($usec, $sec) explode( , microtime());return (float)$usec (float)$sec; }// 记录开始时间 $starttime get_microtime();// 执行10万次获取随机小数 for($i0; $i100000; $i){lcg_value(); }// 记录结束时间 $endtime get_microtime();// 输出运行时间 printf(run time %f ms\r\n, ($endtime-$starttime)*1000); ? 输出run time 86.178064 ms 执行时间上比较因为lcg_value()直接是php原生方法而mt_rand()与mt_getrandmax()需要调用两个方法并需要进行计算因此lcg_value()的执行时间大约快3倍。 2.随机效果比较 基于mt_rand()与mt_getrandmax()算法的随机效果 ?php /*** 生成0~1随机小数* param Int $min* param Int $max* return Float*/ function randFloat($min0, $max1){return $min mt_rand()/mt_getrandmax() * ($max-$min); }header(content-type: image/png); $im imagecreatetruecolor(512, 512); $color1 imagecolorallocate($im, 255, 255, 255); $color2 imagecolorallocate($im, 0, 0, 0); for($y0; $y512; $y){for($x0; $x512; $x){$rand randFloat();if(round($rand,2)0.5){imagesetpixel($im, $x, $y, $color1);}else{imagesetpixel($im, $x, $y, $color2);}} } imagepng($im); imagedestroy($im); ? lcg_value()的随机效果 ?php header(content-type: image/png); $im imagecreatetruecolor(512, 512); $color1 imagecolorallocate($im, 255, 255, 255); $color2 imagecolorallocate($im, 0, 0, 0); for($y0; $y512; $y){for($x0; $x512; $x){$rand lcg_value();if(round($rand,2)0.5){imagesetpixel($im, $x, $y, $color1);}else{imagesetpixel($im, $x, $y, $color2);}} } imagepng($im); imagedestroy($im); ? 以上是“php如何设置随机数”这篇文章的所有内容感谢各位的阅读希望分享的内容对大家有帮助.
http://www.w-s-a.com/news/127082/

相关文章:

  • 怎么优化网站的单个关键词排名惠州品牌网站建设
  • 上海跨境电商网站制作wordpress弃用react
  • phpcms网站模版下载电商网站建设属于研发费用吗
  • 动画毕业设计代做网站高校门户网站建设需要多少钱
  • 网站内链设置wordpress前台特别慢
  • 杭州模板网站建设系统江苏省建设考试网站准考证打印
  • 国家建设执业资格注册中心网站企业手机网站建设机构
  • 内容管理系统做网站怎么做英文版的网站
  • 浙江省专业网站制作网站建设网站设计及内容策划
  • 浙江门户网站建设公司做网站上哪买空间
  • 郑州网站怎么推广贵阳市网站建设
  • 规范网站建设福州外贸网站建设推广
  • 平台电商网站开发传媒公司排行
  • 在哪给人做网站怎么样制作一个网页
  • 网站更改文章标题广西新闻
  • 专业做网站路桥寺院网站建设方案
  • 网站维护与优化教程广州做网站的网络公司排名
  • 网站做贷款许可证网站改版方案模板
  • 装饰公司怎么做网站嘉兴网站制作推广
  • 深圳兼职做网站涿州网站制作
  • 能找本地人做导游的网站app模板素材下载免费
  • 网站积分的作用网站开发需要看相关书籍
  • 建设银行总行网站alexa排名与什么有关系
  • 阿里云服务器发布网站收款网站怎么建设
  • 开发东莞网站制作公司做网站优化步骤
  • 网站版权信息的正确写法如何制作网络游戏
  • 郑州移动端网站建设如何在网上推广自己的公司
  • 企业建站源码系统破解网站后台
  • 石家庄网站开发报价企业注册资本代表什么
  • 招商平台公司宁波seo教程推广平台