Home >Backend Development >PHP Tutorial >Example code of two methods for generating random numbers in PHP. Output random IP_PHP tutorial

Example code of two methods for generating random numbers in PHP. Output random IP_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:30:38982browse

I am an asp programmer. This is my first time writing a php program. I would like to share my experience

Copy the code The code is as follows:

$ip2id= round(rand(600000, 2550000) / 10000); //The first method is to directly generate
$ip3id= round(rand(600000, 2550000) / 10000);
$ip4id= round(rand(600000, 2550000) / 10000);
//The following is the second method, randomly select from the following data
$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;
?>

The example output result is 218.28.131.182
The characteristic of this program is that the first field of the generated IP is within the specified range , the set ones are common domestic number ranges, which means that most of the generated IP addresses are domestic
Core code:
Copy code The code is as follows:

$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.htmlTechArticleI am an asp programmer. This is my first time writing a php program. I would like to share my experience. Copy the code as follows: ? php $ip2id= round(rand(600000, 2550000) / 10000); //The first method, directly...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn