# Conditional structure based on \rand value comparison

I have a simple code that inserts a complex layout for figures and I would like to randomly alternate the position options (for instance, alternating between top and bottom positioning: begin{figure}[t] / [b]). So far, I have been doing this:

\documentclass[11pt, a4paper, frenchb]{article}
\usepackage{polyglossia}
\usepackage[first=0, last=1, quiet]{lcg}

\begin{document}
rand sequence: \rand\arabic{rand}\rand\arabic{rand}
\rand\arabic{rand}\rand\arabic{rand}\rand\arabic{rand}
\rand\arabic{rand}\rand\arabic{rand}\rand\arabic{rand}

\ifthenelse{\equal{\rand\arabic{rand}}{1}}
{align figure to TOP}{align figure to BOTTOM}

\end{document}


but I've got an Undefined control sequence. How can I compare the value returned by the lcg \rand to something common so I can have my figures evenly inserted at the top or bottom across pages.

-

You need to place the \random generation outside the comparison:

\documentclass{article}
\usepackage{xifthen}
\usepackage[first=0, last=1, quiet]{lcg}

\begin{document}
rand sequence: \rand\arabic{rand}\rand\arabic{rand}%
\rand\arabic{rand}\rand\arabic{rand}\rand\arabic{rand}%
\rand\arabic{rand}\rand\arabic{rand}\rand\arabic{rand}

\rand\ifthenelse{\equal{\arabic{rand}}{1}}
{align figure to TOP}{align figure to BOTTOM}

\end{document}


If you're using pdfTeX, the following doesn't require any packages:

\documentclass{article}

\begin{document}
rand sequence: \pdfuniformdeviate2 \pdfuniformdeviate2 \pdfuniformdeviate2 \pdfuniformdeviate2
\pdfuniformdeviate2 \pdfuniformdeviate2 \pdfuniformdeviate2 \pdfuniformdeviate2

\ifnum\pdfuniformdeviate2=0
align figure to TOP
\else
align figure to BOTTOM
\fi

\end{document}

-