Sign in with
Sign up | Sign in
Your question

Need help with a .bat

Last response: in Windows XP
August 10, 2011 2:06:05 PM

Hello, I need to make a program which draws a random number 1-3 twice, but doesn't allow for duplicates.

Here is what I have:

echo off
set /a count=count+1
set /a pool=3*%random%/32768+1
echo %pool%

if %count% == 2 goto !stop!
goto begin~!

set /a count=nul
goto begin~!

As you can see that will pick 2 numbers out of a random num 1- 3, however currently there is nothing to stop it from drawing duplicates. Is there anyway to stop duplicates from being echo'ed ?


More about : bat

August 10, 2011 4:03:28 PM

can you use another variable that you assign the first number to and compare it to the second one drawn.

if the two numbers are the same reduce count by one to run the randomization again

if the second number is different display and exit
August 10, 2011 4:04:40 PM

add an if statement that checks if its a duplicate, if it is go to step for number generation