Two methods of generating random numbers in PHP instance code output random IP
Source: Internet
Author: User
I am an ASP programmer, this is the first time to write PHP program, a little experience sent to share
Copy CodeThe code is as follows:
<?php
$ip 2id= Round (rand (600000, 2550000)/10000); The first method, which directly generates
$ip 3id= Round (rand (600000, 2550000)/10000);
$ip 4id= Round (rand (600000, 2550000)/10000);
Here is the second method, which is randomly sampled in 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);
$ip 1id = $arr _1[$randarr];
echo $ip 1id;
echo ".";
echo $ip 2id;
echo ".";
echo $ip 3id;
echo ".";
echo $ip 4id;
?>
The result of the example output is 218.28.131.182
This program is characterized by the generation of IP first field in the specified range, set a few are common in the country, which means that the generated IP address is mostly domestic
Core code:
Copy CodeThe code is as follows:
<?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 ";
?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service