Let's look at the source code.

Source: Internet
Author: User
For more information, see the source code & lt; html & gt; & lt; head & gt; & lt;/head & gt; & lt; body & gt; & lt ;? Php $ filename & nbsp; = & nbsp; 'English. dat '; & nbsp; // data file name $ refresh & nbsp; = & nbsp; 1; & nbsp; // update cycle (view source code in seconds)






$ Filename = 'English. dat '; // data file name
$ Refresh = 1; // update cycle (in seconds, which can be adjusted as needed)
$ Data = file ($ filename); // load the data file into an array
$ Num_lines = count ($ data); // number of data file lines, that is, the number of records
Mt_srand (floor (time ()/$ refresh ));
$ Id = mt_rand (0, $ num_lines-1); // select a random record number.
$ Content = chop ($ data [$ id]); // select the corresponding data based on the record number and get the last line break
Echo $ content; // output data in javascript format


?>



This is the source code of the regular update page I found on the internet. I would like to ask what it means to implement the regular function without commenting on it. I don't quite understand it. Share:
------ Solution --------------------
Because when the random seed is the same, the order in which mt_rand () is used is certain, that is, the random seed is the same. if mt_rand is called for the first time and mt_rand is called for the first time, the value is 5.

Because time () is the timestamp, that is, the number of seconds. if you set refresh to 30, assume that a time () is 300, so the 30 seconds from here must be 300,301,302,303 ,...... 329

Use 300,301,302,303 ,...... 329 divided by 30, respectively, and the integral part of the quotient is consistent, so
$ Id = mt_rand (0, $ num_lines-1 );
This id does not change in this 30 seconds, so it will definitely change in the next 30 seconds, so it will start to refresh regularly in 30 cycles.

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.