beansandsausages Posted September 24, 2008 Share Posted September 24, 2008 hey, i am trying to make a small random number, ie 0.045 etc ... code i am currently using is: $number = rand(0.000,0.999); it only ever returns the value 0, is there a dirrent function to use? Quote Link to comment https://forums.phpfreaks.com/topic/125620-small-random-number/ Share on other sites More sharing options...
Maq Posted September 24, 2008 Share Posted September 24, 2008 This is because rand() returns a random integer. If you want you could probably take that integer and divide it by 10 x the length of the integer returned by rand()? Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/125620-small-random-number/#findComment-649477 Share on other sites More sharing options...
kenrbnsn Posted September 24, 2008 Share Posted September 24, 2008 The rand() function returns integers. You want to do something like: <?php $r = rand(0,999)/1000; echo number_format($r,3); ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/125620-small-random-number/#findComment-649478 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.