The following functions help you generate pseudorandom numbers. There are wrappers for the randomizing functions offered by your operating system, and there are functions based on the Mersenne Twister algorithm. The Mersenne Twister functions are faster and return numbers with a much better distribution suitable for cryptographic applications. The algorithm was developed by Makoto Matsumoto and Takuji Nishimura. Pedro Melo refactored an implementation by Shawn Cokus in order to add support to PHP.
The getrandmax function returns the maximum random number that may be returned by the rand function.
The mt_getrandmax function returns the maximum random number that may be returned by the mt_rand function.
The lcg_value function returns a number between 0 and 1 using an algorithm called a linear congruential generator, or LCG. This is a common method for generating pseudorandom numbers. The generator is seeded with the process identifier.
integer mt_rand(integer min, integer max)
The mt_rand function uses the Mersenne Twister algorithm to return a number between the two optional arguments, inclusive. If left out, zero and the integer returned by themt_getrandmax function will be used. Use mt_srand to seed the Mersenne Twister random number generator.
The mt_srand function seeds the Mersenne Twister random number generator. It is best to call this function once before using the mt_rand function.
integer rand(integer lowest, integer highest)
The rand function returns a number between the two optional arguments, inclusive. If left out, zero and the integer returned by the getrandmax function will be used. Use the srand function to seed the random number generator.
The srand function seeds the random number generator. It is best to call this function once before using the rand function.
string tempnam(string directory, string prefix)
The tempnam function returns the complete path to a unique temporary filename. This guarantees you will not overwrite an existing file. You must take the responsibility to create and then destroy the file.
The directory argument specifies a directory to put the file in, but it will be discarded if a default temporary directory is defined in an environment variable. Under UNIX this variable is called TMPDIR. Under Windows it is called TMP.You must also specify a prefix for the file, but you may pass an empty string. It's a good idea to pass a meaningful prefix, which will allow you to distinguish between temporary files created by different processes. Note that no suffix is added to the file. Under Windows you may want to add .tmp or some other file extension. An empty string is returned on failure. This function is similar to uniqid.<?
string uniqid(string prefix, boolean use_lcg)
The uniqid function joins the prefix argument to a random series of numbers and letters, which are generated based on the system clock. The prefix may be up to 114 characters long and the unique string is always 13 characters long.If the optional use_lcg argument is TRUE, nine additional characters will be added to the end of the return string These characters are generated by the same algorithm used by the lcg_value function, so they will be a period followed by eight digits. Because the lcg_value function seeds itself with the process ID, turning on this flag may not actually add much randomness.
Compare this function to tempnam.<?
PHP Related Interview Questions
|PHP Interview Questions||MySQL Interview Questions|
|PHP+MySQL Interview Questions||Drupal Interview Questions|
|MYSQL DBA Interview Questions||PHP5 Interview Questions|
|WordPress Interview Questions||Joomla Interview Questions|
|CakePHP Interview Questions||CodeIgniter Interview Questions|
|PHP7 Interview Questions|
An Introduction To Php
Variables, Operators, And Expressions
Classes And Objects
I/o And Disk Access
Time, Date, And Configuration Functions
Parsing And String Evaluation
Sorting Searching And Random Numbers
Integration With Html
Efficiency And Debugging
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.