CMD Random
Posted: 2021-Dec-17, 11:21 am
regarding page https://ss64.com/nt/syntax-random.html and the example shown
---
@ECHO OFF
SET /a _rand=(%RANDOM%*500/32768)+1
ECHO Random number %_rand%
---
I find it not always working. Type the following in CMD and run it multile times:
SET /a _rand=(%RANDOM%*6/32768)+2
It will display random digits 2,3,4,5,6 but it will also sometimes display 7
What works for me is:
---
SET /a _rand=(%random% %% (%high%-%low%+1)) + %low%
---
as part of a line in a CMD file, with high and low being variables containing the upper and lower values.
example directly in cmd:
SET /a _rand=(%random% % (6-2+1)) + 2
run it multile times, it will only display values 2,3,4,5,6
regards
Rob
---
@ECHO OFF
SET /a _rand=(%RANDOM%*500/32768)+1
ECHO Random number %_rand%
---
I find it not always working. Type the following in CMD and run it multile times:
SET /a _rand=(%RANDOM%*6/32768)+2
It will display random digits 2,3,4,5,6 but it will also sometimes display 7
What works for me is:
---
SET /a _rand=(%random% %% (%high%-%low%+1)) + %low%
---
as part of a line in a CMD file, with high and low being variables containing the upper and lower values.
example directly in cmd:
SET /a _rand=(%random% % (6-2+1)) + 2
run it multile times, it will only display values 2,3,4,5,6
regards
Rob