程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php產生隨機數的兩種方法實例代碼 輸出隨機IP

php產生隨機數的兩種方法實例代碼 輸出隨機IP

編輯:關於PHP編程

本人是asp程序員,這是首次寫php程序,一點心得發上來共享
復制代碼 代碼如下:
<?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地址大部分是國內的
核心代碼:
復制代碼 代碼如下:
<?php
$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";
?>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved