php产生随机数的两种方法实例代码 输出随机IP_PHP教程

WBOY
发布: 2016-07-21 15:30:38
原创
963 人浏览过

本人是asp程序员,这是首次写php程序,一点心得发上来共享

复制代码 代码如下:

$ip2id= round(rand(600000, 2550000) / 10000); //第一种方法,直接生成
$ip3id= round(rand(600000, 2550000) / 10000);
$ip4id= round(rand(600000, 2550000) / 10000);
//下面是第二种方法,在以下数据中随机抽取
$arr_1 = array("218","218","66","66","218","218","60","60","202","204","66","66","66","59","61","60","222","221","66","59","60","60","66","218","218","62","63","64","66","66","122","211");
$randarr= mt_rand(0,count($arr_1)-1);
$ip1id = $arr_1[$randarr];
echo $ip1id;
echo ".";
echo $ip2id;
echo ".";
echo $ip3id;
echo ".";
echo $ip4id;
?>

例输出结果为 218.28.131.182
这个程序的特点是,生成的ip第一个字段时在指定范围内的,设定的几个是国内常见号段,也就是说生成的ip地址大部分是国内的
核心代码:
复制代码 代码如下:

$arr_1 = array("http://66.249.89.99","http://66.249.89.104","http://74.125.71.105");
$randarr= mt_rand(0,count($arr_1)-1);
$gip= $arr_1[$randarr];
echo $gip."$randarr";
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/323196.htmlTechArticle本人是asp程序员,这是首次写php程序,一点心得发上来共享 复制代码 代码如下: ?php $ip2id= round(rand(600000, 2550000) / 10000); //第一种方法,直接...
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板