Jump to content

Returning a random number other than 0 and 1


Recommended Posts

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...