954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to generate a double random number by using PHP

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

gondola
Newbie Poster
1 post since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

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?

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

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;
tunde011
Light Poster
40 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You