I'm having a really hard time understanding why the following \ifthenelse check will always result false.
I already used strings and commands in my conditionals and I know that they work. In this particular case though something goes wrong.
To simplify the analysis of this code I'll explain how it should work.
Its objective is to give a random value between 1 and 9 to the counters a and b. Such output is written on the document in the shape of "a=x b=y axby", where x and y are their random values. Then, if the output of a\thea{}b\theb{} is one of a series of given options (a1b1, a2b3, a3b7...) pdflatex will print "TRUE" at the side of the previous line. Otherwise, if such condition is false, it will print "FALSE" instead. Such code is repeated 100 times.
The Random command works pretty well and it will give to the counter #3 a value between #1 and #2. It's built in such a way that it will change seed every time it's called, but the initial seed is given by the document itself. Since it will always create a new seed using the previous seed, what happens is that if you'll use this code you will always have the same output.
So you'll notice that it will always print "FALSE" even though there are some lines on which it should print "TRUE". For example, the fourth one is "a=6 b=1 a6b1". Though, every line will end with FALSE.
I used \ttfamily so it's easier to read.
So here's the MWE.
\documentclass{article}
\usepackage{xifthen}
\usepackage{lcg}
\usepackage{pgffor}
\newcounter{a}
\newcounter{b}
\newcounter{SEED}
\newcommand{\Random}[3]{%
\reinitrand[last=2147483647, seed=\value{SEED}]%
\rand%
\setcounter{SEED}{\therand}%
\reinitrand[first=#1, last=#2, seed=\value{SEED}]%
\rand%
\setcounter{#3}{\value{rand}}%
}
\begin{document}
\ttfamily
\setcounter{SEED}{10}
\foreach \num in {1,...,100} {%
\Random{1}{9}{a}%
\Random{1}{9}{b}%
a=\thea\ b=\theb\ a\thea{}b\theb{} %
\ifthenelse{%
\equal{a\thea{}b\theb{}}{a1b1} \OR %
\equal{a\thea{}b\theb{}}{a2b3} \OR %
\equal{a\thea{}b\theb{}}{a3b7} \OR %
\equal{a\thea{}b\theb{}}{a4b5} \OR %
\equal{a\thea{}b\theb{}}{a5b1} \OR %
\equal{a\thea{}b\theb{}}{a6b1} \OR %
\equal{a\thea{}b\theb{}}{a7b8} \OR %
\equal{a\thea{}b\theb{}}{a9b9}%
}{TRUE}{FALSE}\\
}
\end{document}
I already tried the following measures:
- to put the
a\thea{}b\theb{}parts in an other command; - to use the package
etexand use the\detokenize{}command as suggested in the answer to this (similar) question.
Non of this changed the result at all.
The previously linked thread also suggests using some TeX's commands but I didn't understand how to use different conditions separed by OR, so I don't know if those work. Anyway, I'd prefer a LaTeX based solution unless the TeX one is really easier.

a1{}b1{}is visibly different from the stringa1b1so those tests will never be true. drop the{}– David Carlisle Apr 01 '17 at 16:09ifthenelsecondition? – il mietitore Apr 01 '17 at 16:15\equalis doing an\ifxtest on the definition of the internal commands,\def\tempa{a1b1}and\def\tempb{a1{}b1{}}may print the same way if you print them but they have different definitions and for example\typeout{\tempa}would clearly be different to\typeout{\tempb}– David Carlisle Apr 01 '17 at 16:18