smithmr8 Posted February 25, 2008 Share Posted February 25, 2008 How do I generate random numbers. Im looking to generate random numbers between 0.01 and 5.00 Thanks Link to comment https://forums.phpfreaks.com/topic/92958-generate-random-decimals/ Share on other sites More sharing options...
rhodesa Posted February 25, 2008 Share Posted February 25, 2008 PHP can't generate random numbers with decimals (to my knowledge). But you can generate an integer and divide it by 100 <?php $num = rand(1,500) / 100; echo $num; ?> Link to comment https://forums.phpfreaks.com/topic/92958-generate-random-decimals/#findComment-476248 Share on other sites More sharing options...
kenrbnsn Posted February 25, 2008 Share Posted February 25, 2008 You use the rand() function which generates random integers, then divide by 100 and use the result <?php $x = rand(1,500)/100; echo number_format($x,2); ?> Ken Link to comment https://forums.phpfreaks.com/topic/92958-generate-random-decimals/#findComment-476251 Share on other sites More sharing options...
smithmr8 Posted February 25, 2008 Author Share Posted February 25, 2008 Ah, I see. Thanks Link to comment https://forums.phpfreaks.com/topic/92958-generate-random-decimals/#findComment-476252 Share on other sites More sharing options...
rhodesa Posted February 25, 2008 Share Posted February 25, 2008 Is there an echo in this room or is it just me? Link to comment https://forums.phpfreaks.com/topic/92958-generate-random-decimals/#findComment-476257 Share on other sites More sharing options...
kenrbnsn Posted February 25, 2008 Share Posted February 25, 2008 I was posting my answer at about the same time you posted yours. When I started to post, there were no answers posted. Ken Link to comment https://forums.phpfreaks.com/topic/92958-generate-random-decimals/#findComment-476260 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.