Let's say I have two possible questions. I want only one to be on the generated PDF and I want this one to be randomly selected among the two potential candidates.
I thought this would be sufficient: (minimal code)
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfmathifthenelse{\pgfmathrnd >= 0.5}{%
My first question.%
Potentially has more than one line.%
}{%
My second question%
Potentially has more than one line%
}
\end{document}
This seems logical to me: I generate a random number between 0 and 1, if it's greater than 0.5 I have a version, if it's lower than 0.5 I have another version, and since the random number is generated at each compile I have one of the two versions at each compile.
However, I get loads of errors. I figured that maybe I can't break the {...}
of the \ifthenelse
across lines, so for the sake of understanding I tried
\ifthenelse{\pgfmathrnd >= 0.5}{A}{B}
But still to no avail. I don't really understand if it should be A
of "A"
but the latter doesn't work either.
I also tried using etoolbox
but without better results. (And as far as I understand it, the toggle
has to be declared in the preamble, and in the best of words my two possible questions would be in a separate file that I would just input
into the main file.)
Background and why I want to do that
I am doing a pen-and-paper experiment (think of it as a quiz or a survey). Questions have two possible answers. I want the order of the answers to be random to prevent order effects. Hence I want the question to be randomly
This is the text of the question.
(1) Answer alpha
(2) Answer gamma
Please answer (1) or (2)
or
This is the text of the question.
(1) Answer gamma
(2) Answer alpha
Please answer (1) or (2)
Say my experiment is a file total.tex
and my questions are in a questions.tex
. If I have 10 subjects, I will loop 10 times on the \include{questions.tex}
to generate 10 decision sheets. I want those 10 decision sheets to be randomly different, hence my question.
\pgfmathsetseed{1234}
(1234 being the seed). Every time you compile you'll get the same random sequence; the individual sheets in the same document however will be different from each other.\ifthenelse
doesn't know>=
and doesn't accept decimal numbers.\ifthenelse
is not a LaTeX command, are you including other packages such asifthen
?\pgfmathifthenelse
not simply\ifthenelse
.