
Checking if 3 random numbers are same
Moderator: DosItHelp
Checking if 3 random numbers are same
Hi,do you know a game called Jackpot ? i think most of people know whats it.I know how to make a random number generator etc,but i want to know how to check if those 3 numbers are same,so if it will put 3 3 3 you will win.I thought about IF %random1% eq %random2% (im not sure about eq,i know there was a command like that but i forgot how it was called
,eq or equ,i mean about equal)

Re: Checking if 3 random numbers are same
Greetings silent,
I am not familiar with Jackpot but maybe this will help.
Type if /? at a command prompt and you will find;
EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal
Best wishes.
I am not familiar with Jackpot but maybe this will help.
Type if /? at a command prompt and you will find;
EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal
Best wishes.
Re: Checking if 3 random numbers are same
In this instance all you really need to do is compare it as as string. You don't need to use the extended compare operators.
Then why don't you look at the help for the IF command.
Code: Select all
IF "%R1%"=="%R2%" (
IF "%R1%"=="%R3%" SET VAR=YES
)
silent wrote:(im not sure about eq,i know there was a command like that but i forgot how it was called,eq or equ,i mean about equal)
Then why don't you look at the help for the IF command.
Re: Checking if 3 random numbers are same
You need to combine an IF command inside another one to assemble an AND operator, that is, IF R1 == R2 IF R1 == R3 ... I suggest you to made this point clear by creating an auxiliary variable called AND this way:
Code: Select all
SET AND=IF
IF %R1% == %R2% %AND% %R1% == %R3% ECHO YOU WIN
Re: Checking if 3 random numbers are same
Aacini wrote:I suggest you to made this point clear by creating an auxiliary variable called AND this way:Code: Select all
SET AND=IF
IF %R1% == %R2% %AND% %R1% == %R3% ECHO YOU WIN
I wouldn't find that too clear in general. It could easily mislead one to write...
Code: Select all
IF %R1% == %R2% %AND% %R1% == %R3% (ECHO YOU WIN) ELSE (ECHO YOU LOSE)
Liviu
Re: Checking if 3 random numbers are same
Liviu has a good point
----------------------------------
Using a bit of math, it is possible to roll the dice and get the result with a single SET statement. Then a simple IF statement prints out the result.
Dave Benham

----------------------------------
Using a bit of math, it is possible to roll the dice and get the result with a single SET statement. Then a simple IF statement prints out the result.
Code: Select all
@echo off
setlocal enableDelayedExpansion
set /a "r1=!random!%%10, r2=!random!%%10, r3=!random!%%10, result=^!(r1-r2)&^!(r1-r3)"
if !result!==1 (echo WINNER^^^!) else echo You lose
Dave Benham
Re: Checking if 3 random numbers are same
Even without math you could create a single IF
jeb
Code: Select all
@echo off
set /a r1=%random% %% 10
set /a r2=%random% %% 10
set /a r3=%random% %% 10
echo "%r1%,%r2%,%r3%"
if "%r1%,%r2%,%r3%"=="%r2%,%r3%,%r1%" echo All same
jeb
Re: Checking if 3 random numbers are same
jeb wrote:Even without math you could create a single IFCode: Select all
@echo off
set /a r1=%random% %% 10
set /a r2=%random% %% 10
set /a r3=%random% %% 10
echo "%r1%,%r2%,%r3%"
if "%r1%,%r2%,%r3%"=="%r2%,%r3%,%r1%" echo All same
jeb
Nice jeb. This just shows how we sometimes over complicate things and again you show us how to keep it simple.
Re: Checking if 3 random numbers are same
@jeb - I like the way you think
It took me a moment to notice the string rotation in the comparison. As long as we are restricted to single digit numbers, then the commas are not needed. Two digits or more and the commas are definitely needed.
Dave Benham

It took me a moment to notice the string rotation in the comparison. As long as we are restricted to single digit numbers, then the commas are not needed. Two digits or more and the commas are definitely needed.
Dave Benham
Re: Checking if 3 random numbers are same
jeb wrote:Code: Select all
if "%r1%,%r2%,%r3%"=="%r2%,%r3%,%r1%" echo All same
Nice! In the name of readability^H^H terseness I submit this works as well

Code: Select all
if "%r1%,%r2%"=="%r2%,%r3%" echo All same
Liviu