Random generator in the batch

前端 未结 6 1988
走了就别回头了
走了就别回头了 2020-11-27 23:20

I have a bat file

@echo %RANDOM%

and execute it using command line

start randomcheck.bat & start randomcheck.bat
         


        
6条回答
  •  清歌不尽
    2020-11-27 23:44

    $RANDOM in bash does not have this flaw.

    @echo win=%RANDOM%
    
    @for /f %%i in ('bash -c "echo $RANDOM"') do @set VAR=%%i
    
    @echo cygwin=%VAR%
    

    prints the same windows numbers but distinct cygwin ones when I run start randomcheck.bat & start randomcheck.bat. Using cygwin is better than writing a separate VBScript for a single command. Might be you can teach me how to replace the bash -c "echo $RANDOM" with the windows scripting host alternative, which would eliminate the need for installing the cygwin.

提交回复
热议问题