Yeodan Posted May 12, 2009 Share Posted May 12, 2009 How do I make php generate a random number with two numbers behind the . for me? I have this: $min can be something like 1 or 1.58 $max can be something like 2 or 2.58 $damage = rand($min, $max); Link to comment https://forums.phpfreaks.com/topic/157816-solved-randoms-like-158/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2009 Share Posted May 12, 2009 $min = 158; $max = 258; $damage = rand($min, $max)/100.0; echo $damage; Link to comment https://forums.phpfreaks.com/topic/157816-solved-randoms-like-158/#findComment-832334 Share on other sites More sharing options...
Adam Posted May 12, 2009 Share Posted May 12, 2009 There's probably a function to produce random decimals, but you could use: $damage = number_format(rand(1, 999), 2, '.'); .. not tested. Link to comment https://forums.phpfreaks.com/topic/157816-solved-randoms-like-158/#findComment-832335 Share on other sites More sharing options...
redarrow Posted May 12, 2009 Share Posted May 12, 2009 <?php $large_number=rand(1,9); $small_number=rand(01,99); $res=$large_number.'.'.$small_number; echo $res; ?> Link to comment https://forums.phpfreaks.com/topic/157816-solved-randoms-like-158/#findComment-832336 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.