php - How to get integer between two values from stream of bits? -


i have project uses php's mt_rand() generate different random integers have gained access stream of real random bits. having trouble figuring out how create function similar mt_rand(), can random integer between 2 values, stream of bits. how can achieve this?

i read php_int_size * 8 bits , squash resulting number in range need:

function squash($nr, $min, $max) {     return $min + $nr % ($max - $min); } 

another way:

function squash($nr, $min, $max) {     return $min + round($nr / php_int_max * ($max - $min)); } 

this occurred me, why not use random stream , push mt_srand():

function squash($nr, $min, $max) {     mt_srand($nr);     return mt_rand($min, $max); } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -