halion Posted July 2, 2004 Share Posted July 2, 2004 I'm trying to figure out a way to return a random number between 0 and 90 but only by tens like 0, 10, 20 etc until 90. Now I know the rand function returns 0 or 1 so I'm wondering how can I go about doing this? Quote Link to comment Share on other sites More sharing options...
malexander Posted July 2, 2004 Share Posted July 2, 2004 You'll need to use a combination of rand() and floor() functions: floor(rand($T)*(9+1))*10 The argument to rand() is the seed. Calling rand with the same seed will return the same value, so you'll need to vary it (either with $T, $PT or similar variables). Multiplying by 9+1 is done so that the fractional numbers are in the range 0-10 (with exactly 10 not ever occurring, I believe). floor'ing it returns only the integer portion, 0-9. Multiply by 10 afterwards and you've got 0,10,20, ... 90. Quote Link to comment Share on other sites More sharing options...
halion Posted July 2, 2004 Author Share Posted July 2, 2004 Thanks for the help. Its working pretty well just needs alittle tweaking. 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.
Note: Your post will require moderator approval before it will be visible.