This picks a number from 10-25 but im still confused why it works
It works because, in this line:
set /a R=%random%%% 16 +10
1.
%random% selects a random number between 0 and 32767
2.
%% 16 takes the remainder after dividing it by 16. This will be between 0 and 15
3.
+ 10 adds 10 to that giving a number between 10 and 25.
To get a random number between X and Y where X is the lowest number and X is the highest number allowed, take %random% modulo ((Y-X)+1) and then add Y.
This means: (using your numbers)
From the highest number (25), take away the lowest number (10).
25 - 10 = 15
To this, add 1
15 + 1 = 16
So you make set /a do this: %random% %% 16
The result will be between 0 and 15.
Now you add the lowest number (10)
This gives you a number between 10 and 25
i know it's not the best method so please post if you have a better idea.
Given the limited tools available in batch scripting, it isn't bad. It is quick to run and is only one line of code. A strict mathematician might say that the results are pseudo-random. It depends what you want it for. It is OK for a batch game you are writing for a learning exercise or if you are playing around.