[Tex/LaTex] How to resolve an incomplete \iffalse error

conditionalstikz-pgf

I'm trying to create a multitude of 8×8 grids with a single random shaded box on each. This is for a classroom activity and I want a bunch of different grids and would rather not hard-code the random box for each one. I'm using the following code:

\begin{tikzpicture}[x=2.54cm, y=2.54cm]
    \foreach \y in {1,2,...,8}
    {
        \foreach \x in {1,2,...,8}
        {
            \ifthenelse{\x= \pgfmathparse{random(8)}\pgfmathresult \AND \y=\pgfmathparse{random(8)}\pgfmathresult}
            {\filldraw[draw=black,fill=lightgray] (\x,\y) rectangle (\x,\y) rectangle (1+\x,1+\y);}
            {\draw[black] (\x,\y) rectangle (\x,\y) rectangle (1+\x,1+\y);}
        }
    }
\end{tikzpicture}

And I get the error

Incomplete \iffalse; all text was ignored after line 51"

where line 51 is that close curly brace before the \end{tikzpicture}. I've looked around for a fix but haven't discovered one yet.

Best Answer

Just fleshing out David's comments.

\documentclass{standalone}
\usepackage{ifthen}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[x=2.54cm, y=2.54cm]
\pgfmathtruncatemacro{\RandomX}{random(8)}
\pgfmathtruncatemacro{\RandomY}{random(8)}
    \foreach \y in {1,2,...,8}
    {
        \foreach \x in {1,2,...,8}
        {
            \ifthenelse{\x=\RandomX  \AND \y=\RandomY}
            {\filldraw[draw=black,fill=lightgray] (\x,\y) rectangle (\x,\y) rectangle (1+\x,1+\y);}
            {\draw[black] (\x,\y) rectangle (\x,\y) rectangle (1+\x,1+\y);}
        }
    }
\end{tikzpicture}
\end{document}

And @cfr is right, but this also works.

Related Question