Create a random number and check if it is odd or even

后端 未结 2 904
孤独总比滥情好
孤独总比滥情好 2021-01-27 19:48

I am looking to create a batch file that, when ran, creates a random integer from 0 to 100 and then runs it through an if statement that checks whether it is odd or even. I\'ve

2条回答
  •  春和景丽
    2021-01-27 20:04

    The following prints a random number between 0 and 99, and prints whether it's even or odd:

    @echo off
    
    set /a num = %random% %% 100
    echo %num%
    set /a odd = num %% 2
    if %odd% EQU 1 (echo odd) else (echo even)
    

提交回复
热议问题