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 Quote Link to comment 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; ?> Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
smithmr8 Posted February 25, 2008 Author Share Posted February 25, 2008 Ah, I see. Thanks Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.