Generally, numbers are widely used in day-to-day life, as well as in computer applications. Every programming language has built in specific functions to deal
with numbers.
In PHP programming language, the numbers are classified in two main categories: integers and floating point numbers. The advantage of this programming language reside in its capability to automatically convert integers to floating point numbers and reverse. For example, the value of a fraction written in the form 5/2 will be interpreted as being 2.5.
The true problem in numbers manipulation occurs when you need to generate random numbers for a certain purpose. The properties of random numbers will not be discussed in this article, but they could be of different types, depending on their destination of usage. In server side scripting, random numbers generators and functions that produce them are employed in creation of the security systems as captcha images, password encryption applications, games and more.
In PHP programming language there are two basic functions that returns random numbers: rand(a,b) and mt_rand(a,b). The a and b parameters represents the minimum, respectively the maximum integer value defining the range in which the random number will be produced. If those functions are called without parameters, they will return a random integer situated between 0 and a maximum value, which depends on the operating system type.
The mt_rand() function uses Mersenne Twister algorithm for random number generation, which means that the quality of random numbers is much better as compared to those resulted from the call of rand() function, because the last one is based on a simpler random number generator that creates predictable random numbers sequences. For example, if you run the next code many times, you will notice the difference in random numbers generation between mt_rand() and rand() functions:
In practice, it is recommended to select and test a certain random numbers generator using statistical methods in order to determine the random numbers "quality". This aspect is very important in PHP applications based on random numbers, like a random image display script or an ads rotating application.