Random PHP (w/AJAX)
This page implements a random number (and string) generator. The form below provides a way to test the functions. The PHP source code for the RandNumber and RandString functions is available from the links. To avoid multiple POSTs and page reloading, the value generation is done using a JavaScript AJAX call. This is done using the Prototype JavaScript framework.
PHP Random
PHP has two different functions for generating random number, rand() and mt_rand(), which is more random and faster than rand(). This example uses the mt_rand() function.
Random numbers - source code
The example generates a number in the range of 0 to maximum with maximum being the value returned by the mt_getrandmax() function.
Random strings - source code
The example generates a string of random numbers, uppercase letters and lowercase letters depending on the character types included. This is done by getting a random number in three ranges using the ASCII values for the "0-9", "A-Z", and "a-z" characters. These are then combined and added to the result until the requested number of characters has been obtained.
PHP has two different functions for generating random number, rand() and mt_rand(), which is more random and faster than rand(). This example uses the mt_rand() function.
Random numbers - source code
The example generates a number in the range of 0 to maximum with maximum being the value returned by the mt_getrandmax() function.
Random strings - source code
The example generates a string of random numbers, uppercase letters and lowercase letters depending on the character types included. This is done by getting a random number in three ranges using the ASCII values for the "0-9", "A-Z", and "a-z" characters. These are then combined and added to the result until the requested number of characters has been obtained.