How to use random in BATCH script?
相关问题
- Inheritance impossible in Windows Runtime Componen
- how to get running process information in java?
- Is TWebBrowser dependant on IE version?
- How can I have a python script safely exit itself?
- I want to trace logs using a Macro multi parameter
相关文章
- 如何让cmd.exe 执行 UNICODE 文本格式的批处理?
- 怎么把Windows开机按钮通过修改注册表指向我自己的程序
- Warning : HTML 1300 Navigation occured?
- Bundling the Windows Mono runtime with an applicat
- Windows 8.1 How to fix this obsolete code?
- why 48 bit seed in util Random class?
- How do I get to see DbgPrint output from my kernel
- CosmosDB emulator can't start since port is al
And just to be completely random, a total lack of order:
SET /A V=%random% %%15 +1
simplified with multiple IF statements and plenty of ((()))
example "
will give a random number between 100 and 50. Be sure to only use one percentage sign as the operand if you are not using the line in a batch script!
You'll probably want to get several random numbers, and may want to be able to specify a different range for each one, so you should define a function. In my example, I generate numbers from 25 through 30 with
call:rand 25 30
. And the result is inRAND_NUM
after that function exits.%RANDOM%
gives you a random number between 0 and 32767.Using an expression like
SET /A test=%RANDOM% * 100 / 32768 + 1
, you can change the range to anything you like (here the range is [1…100] instead of [0…32767]).