## CMD Random

Microsoft Windows
Rob
Posts: 1
Joined: 2021-Dec-17, 11:05 am

### CMD Random

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
Posts: 5
Joined: 2021-Aug-03, 1:45 am

### Re: CMD Random

I did an analysis of the two random number generation methods a while back and posted it on Reddit: https://www.reddit.com/r/Batch/comments ... lying_and/

Code: Select all

``set /a rnd=(%RANDOM%%%(max-min+1))+min``
is a more even distribution anyway.
Simon Sheppard
Posts: 83
Joined: 2021-Jul-10, 7:46 pm
Contact:

### Re: CMD Random

When you divide %RANDOM% by 32768 you will get a random number between 0 and almost 1 (0.999969)
notice we are dividing by 32768 rather than 32767, so we should never get 1 which would give us an uneven distribution of numbers.

if you multiply that by 6 you will get a random number between 0 and 5.9999
If you add 2 you now get a random number between 2 and 7.9999
when rounded down that becomes 2 to 7 as you have found

So if you want a higher starting point without changing the maximum possible value then you need to add 2 but only multiply by 5
giving a random number between 0 and 4.9999
You add 2 to get a random number between 2 and 6.9999
when rounded down that becomes 2 to 6.

Code: Select all

``SET /a _rand=(%RANDOM%*5/32768)+2``
{"ft_lang_label":"__label__en","ft_lang_prob":0.85184556,"math_prob":0.9431476,"size":2471,"snap":"2022-27-2022-33","text_gpt3_token_len":747,"char_repetition_ratio":0.14065666,"word_repetition_ratio":0.546875,"special_character_ratio":0.32254148,"punctuation_ratio":0.0989011,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9764317,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-07-03T17:56:42Z\",\"WARC-Record-ID\":\"<urn:uuid:9db6a394-14b4-4104-abdd-58311f819c5d>\",\"Content-Length\":\"28564\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ee2ab725-86a8-452b-8a3e-ae4e90dc2084>\",\"WARC-Concurrent-To\":\"<urn:uuid:004a8d62-9ec4-45c8-a748-8029c47c18f3>\",\"WARC-IP-Address\":\"216.92.75.79\",\"WARC-Target-URI\":\"https://ss64.org/viewtopic.php?f=2&t=383&sid=afd2a32be751c6e03b122dc839d813fd\",\"WARC-Payload-Digest\":\"sha1:7HBWWBGZEAAMEBFTBDIKURAGQCKE4KEQ\",\"WARC-Block-Digest\":\"sha1:B7UBUVL7N4FCE7KUF7LYCX3DQN72TMEM\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656104248623.69_warc_CC-MAIN-20220703164826-20220703194826-00579.warc.gz\"}"}