Could someone tell me how to generate a double random number by using PHP? THanks.

Member Avatar for iamthwee

If you know how to generate one random number, surely you can generate two? I presume you have the intelligence to go to google and type in random numbers php?

lol. Well i hae created a function which should help.

function getdoublenumbers($units_min,$units_max,$tens_min, $tens_max){

$units = rand($units_min, $units_max);

$tens = rand($tens_min, $tens_max);

$doublenumber = "$units.$tens";

return $doublenumber;

}

$string4 = getdoublenumbers(0,4,01,99);

if(strlen($string4) == 3){ // incase the double is 4.0

	$string4.="0"; // add another 0 to it so it becomes 4.00
}
echo $string4;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.