Two methods for generating random numbers in php: instance code output random IP

Source: Internet
Author: User

I am an asp programmer. This is the first time I have written a php program.
Copy codeThe Code is as follows:
<? Php
$ Ip2id = round (rand (600000,255 0000)/10000); // The first method is directly generated.
$ Ip3id = round (rand (600000,255 0000)/10000 );
$ Ip4id = round (rand (600000,255 0000)/10000 );
// The second method is as follows:
$ 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 sample output is 218.28.131.182.
The feature of this program is that the first field of the generated ip address is within the specified range, and several are common Chinese number segments. That is to say, most of the generated ip addresses are in China.
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 ";
?>

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.