Randomizing
Randomizing
(OP)
How do you get a random number between numbers like 40 and 50.
A = int(15 * rnd + 1)
This gives 1 - 15.
A = int(50 * rnd + 40)
This gives numbers up to 80...what am I doing wrong...?
A = int(15 * rnd + 1)
This gives 1 - 15.
A = int(50 * rnd + 40)
This gives numbers up to 80...what am I doing wrong...?
RE: Randomizing
A = INT((50 - 40 + 1) * RND + 40)
A = INT(11 * RND + 40)
Alt255@Vorpalcom.Intranets.com
RE: Randomizing
The rule of converting ranges is that whatever you do your number you also do to both ends of the range.
That said, the following function will concisely return an integer inside the specified range, inclusively at both ends:
FUNCTION getRandomInteger%(leastNumber%, greatestNumber%)
rangeSize% = greatestNumber% - leastNumber% + 1
getRandomInteger% = (rangeSize% * RND) + leastNumber%
END FUNCTION