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.