Scalable If/Then Structure

An ideal usecase for luatex:

\documentclass[margin=1mm, varwidth=true]{standalone}
\usepackage{luacode}

\begin{luacode}
  userdata = userdata or {}

  local questions = {
      "1 + 2 = 3" ,
      "2 + 1 = 3" ,
      "3 = 2 + 1" ,
      "3 = 1 + 2" ,
    }

  function userdata.fact()
    local A = math.random(#questions)
    tex.print(questions[A])
  end
\end{luacode}

\newcommand\Fact{\luadirect{userdata.fact()}}

\begin{document}

\begin{itemize}
  \item $\Fact$ 
  \item $\Fact$ 
  \item $\Fact$ 
  \item $\Fact$ 
  \item $\Fact$
\end{itemize}

\end{document}

which gives

enter image description here


If you have 100 different cases, then your code logic is wrong at some point. But for not too many cases you can do \ifcase

\documentclass{article}
\usepackage{pgfmath}

\pgfmathsetseed{\number\pdfrandomseed}
\pgfmathtruncatemacro{\A}{random(1,4)}

\begin{document}

\ifcase\A\relax%
  \or 1+2=3% Because \A starts from 1
  \or 2+1=3%
  \or 3=2+1%
  \or 3=1+2%
\fi

\end{document}

I think it's easy to define essentially an array of options so you can define or redefine them as needed without having to define them all together in a nested structure.

\documentclass{article}

\usepackage{pgffor}

\usepackage{ifthen}

\pagestyle{empty}
\setlength{\parindent}{0pt}

% THE FOUR EQUATIONS
% 1.   1+2=3
% 2.   2+1=3
% 3.   3=2+1 
% 4.   3=1+2

\def\defchoice#1#2{\expandafter\def\csname X-#1\endcsname{#2}}
\defchoice{1}{$1+2=3$}
\defchoice{2}{$2+1=3$}
\defchoice{3}{$3=2+1$}
\defchoice{4}{$3=1+2$}

\pgfmathsetseed{\number\pdfrandomseed}

\newcommand{\InitVariables}
{\pgfmathsetmacro{\A}{random(1,4)}} 

\newcommand*{\onefact}
{%%%%%%%%%% dont forget % at end of line
 \InitVariables
  \csname X-\A\endcsname}


\newcommand{\myequations}[1]
{%
 \foreach \x in {1,...,#1}
  {\onefact\par}% don't end a paragraph with \\
}

\begin{document}

\myequations{10} 

\end{document}