get a uniformly distributed random number in php

To get a uniformly distributed random number in PHP, you can use the rand() or mt_rand() functions. Both functions generate a random integer between two given values.

For example, to generate a random integer between 1 and 10, you can use the rand() function like this:

main.php
$rand_num = rand(1, 10);
echo $rand_num;
41 chars
3 lines

Alternatively, you can use the mt_rand() function, which is generally faster and uses the Mersenne Twister algorithm for generating random numbers:

main.php
$rand_num = mt_rand(1, 10);
echo $rand_num;
44 chars
3 lines

Both functions will return a random integer between 1 and 10 with a uniform distribution.

gistlibby LogSnag