RANDOM NUMBERS
-
is there any way to generate random numbers ranging between 10 to 100
-

-
@miro1360 thanks miro
-
@zackry I did an update
-
@miro1360 absolute perfection , thanks a bunch , it works like a charm.
-
The answer given by @miro1360 is not quite correct and overly complicated. It unnecessarily checks itself and tries again whenever it generates a number outside of the 10-100 range. So why not instead update the block that generates the number so that it never generates a number outside of the 10-100 range? Also, you should not divide by 32768 because the max of MathRand() is 32767. Dividing by 32768 means you will sometimes get a value larger than 100. Additionally, this random number generating actually produces numbers 10-110, which is probably why there is a block to check if the value is within range. I feel my example is better and simpler. It also properly seeds the random number generator.

-
@sidmcfarland said in RANDOM NUMBERS:
The answer given by @miro1360 is not quite correct and overly complicated. It unnecessarily checks itself and tries again whenever it generates a number outside of the 10-100 range. So why not instead update the block that generates the number so that it never generates a number outside of the 10-100 range? Also, you should not divide by 32768 because the max of MathRand() is 32767. Dividing by 32768 means you will sometimes get a value larger than 100. Additionally, this random number generating actually produces numbers 10-110, which is probably why there is a block to check if the value is within range. I feel my example is better and simpler. It also properly seeds the random number generator.

- my example could divide by one more as the max value 32767, it will not break the code, yes I used the condition
- it was just a fast usable reply, sorry if it is "OVERLY" complicated :D, everything can be improved (so your example, because MathSrand)

- MathRand can be used alone, without MathSrand it does a self initialization with a random seed on every call, which is more random than fixing it to a tickCount which overflows every 49 days (and than repeats), ... initializing with MathSrand is good only for a recurring sequence (like for testing purposes to achieve the same result) ...