Method 1 <? Php $ FileID = date ("Ymd-His"). '-'. rand (100,999); // $ FileID is a random number such as 20100903-132121-908?> Method 2 <? Phpfunction randomkeys ($ length) {$ returnStr = ''; $ pattern = 'hangzhou'; for ($ I = 0; $ I <$ length; $ I ++) {$ returnStr. = $ pattern {mt_rand (0, 61)}; // generate a php random number} return $ returnStr;} echo randomkeys (4);?> Method 3 <? Php // seed user-defined functions use microseconds as the seed function seed () {list ($ msec, $ sec) = explode ('', microtime (); return (float) $ sec;} // broadcast the seed of the random number generator, and use the srand function to call the returned result srand (seed () of the seed function; // output the random number, the random number range is 10-100 echo rand (10,100);?> Is the above and below no different? They all randomly output numbers between 10-. It's too easy for new people to learn. <? Php echo rand (10,100);?> Mt_rand (10,100); srand is the seed. If it is not set, the default value is 1 rand. Generally, it is a fixed operation of parameters using the seed. You can try it out, no seed or set a fixed seed. Run rand and close the browser and then run rand. You will find that the result is always the same. Let's talk about the rand () function first, rand ([int min], [int max]) This function obtains a random number between min and max. If the maximum and minimum ranges of random numbers are not specified, this function automatically retrieves a random number from 0 to RAND_MAX. However, if you only use the rand () function, the random number is messy. You 'd better use the srand () function before getting the random number each time to configure the new random number seed. Explain the usage of the following functions (these two functions are generally used in this way): srand (double) microtime () * 1000000); $ rand_number = rand (); microtime () two values are returned: The current millisecond and timestamp. to extract a random number, we can only get a random number from the millisecond. (double) microtime () returns only the current millisecond value. Microtime () is the number of milliseconds in seconds, so the values are decimal places. Multiply by 1000000 to convert them into integers. Their workflow is as follows: (1): first, give srand () provides a "Seed";, which is a value of the unsigned_int type. (2): _ then, call rand (), which returns a random number (in the range of _ 0 ~) based on the value provided to srand ~ Between 32767) (3): Call rand () multiple times as needed to continuously obtain new random numbers. (4): Whenever srand () can be provided with a new "Seed" to further "randomize" the output results of rand.