Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: How to make batch file do a random choice?  (Read 9831 times)

0 Members and 1 Guest are viewing this topic.

Whitebeard1

    Topic Starter


    Intermediate

    Thanked: 2
    • Computer: Specs
    • Experience: Familiar
    • OS: Mac OS
    How to make batch file do a random choice?
    « on: June 02, 2014, 02:36:17 AM »
    Hey, I'm trying to make a batch file that can randomly choose between two scripts.
    For example, the first option can be 'echo you win', and the second can be 'echo you lose'.
    Is it possible for the batch file to randomly choose on of them?
    Thanks,
    Whitebeard1
    « Last Edit: June 02, 2014, 03:09:21 AM by Whitebeard1 »
    Computers follow your orders, not your intentions.

    foxidrive



      Specialist
    • Thanked: 268
    • Experience: Experienced
    • OS: Windows 8
    Re: How to make batch file do a random choice?
    « Reply #1 on: June 02, 2014, 03:26:42 AM »
    See if this is the sort of thing you need.

    Code: [Select]
    @echo off
    :loop
    set /a num=%random% %% 2
    if %num% equ 0 (echo you win) else (echo you lose)
    pause
    goto :loop

    Whitebeard1

      Topic Starter


      Intermediate

      Thanked: 2
      • Computer: Specs
      • Experience: Familiar
      • OS: Mac OS
      Re: How to make batch file do a random choice?
      « Reply #2 on: June 02, 2014, 05:03:31 AM »
      Thanks a bunch! Exactly what I need. ;D
      Computers follow your orders, not your intentions.