posted 23 years ago
At the risk of being redundant I wanted to clarify what I was saying so you could understand it a bit more. Again the formula is this
Math.random()*(rangeOfNumbersInYourSet) + startingPoint
If you wanted to create a list of numbers from 30 to 40 (including the ending points 30 and 40), there are 11 numbers in the list so your range would have 11 in it. You have to remember when you are subtracting numbers, you are actually counting the spaces between the numbers. Not the numbers themselves. If you want to count the numbers, you always need to add 1. Example - If I want a range of numbers from 0 to 4 (including 4), I need to tell the system 5. Reason being is that there are 5 numbers in my set. 0, 1, 2, 3, 4. I should have altered my formula to state the following
Math.random()*(rangeOfNumbersInYourSet + 1) + startingPoint
This usually appropriate since most people assume the range will include the last element in the list. So again if I wanted a range of numbers from 300 to 350, (including 350) it would look like this.
Math.random()*(350 - 300 + 1) + 300
Regards,
Dale DeMott
------------------
By failing to prepare, you are preparing to fail.
Benjamin Franklin (1706 - 1790)
By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)