Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.