5

Last year, I came up with a solution to randomly display the names of my students in a presentation using the package tikz. Unfortunately, I'm not a LaTeX guru, and it's far from perfect:

  1. Compilation is really slow (I've heard for loops should be forbidden...).
  2. The random generator doesn't seem to have a nice uniform distribution (at least for every seeds).
  3. I need to manually set a seed.

Actually, point 1. is what really matters for me.

How would you randomly display a word from a list of words previously defined?


Here the solution I'm using until now:

\documentclass[french]{beamer}
\usepackage{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}

\pgfmathdeclarerandomlist{classe}{{Adeline}{Apolline}{Alric}{Jana}{Alex}{Axel}{Baptiste}{Océanne}{Joris}{Lucas C.}{Esteban}{Margaux}{Emma F.}{Louis}{Nathan}{Grégoire}{Jérémy}{Emma L.}{Mélina}{Arthur}{Lea}{Laurette}{Flora}{Manon}{Julie}{Lucas T.}{Maëva}}
\newcommand{\eleve}[1]{
\pgfmathsetseed{1} % seed I need to change
\foreach \i in {0,...,#1}{\pgfmathrandomitem{\a}{classe}}
\pgfmathrandomitem{\a}{cinquiemed} \a
}

\begin{document}
\begin{frame}
\begin{enumerate}
  \item<1-> $9 \times 7 = \action<3->{63}$ \hfill \action<2->{\eleve{0}}
  \item<4-> $12 \times 12 = \action<6->{144}$ \hfill \action<5->{\eleve{1}}
  \item<7-> $6 \times 7 = \action<9->{42}$ \hfill \action<8->{\eleve{2}}  
\end{enumerate}
\end{frame}
\end{document}

And you can look at the last slide below to see the result: enter image description here

remjg
  • 2,486
  • 2
    See http://tex.stackexchange.com/questions/109619/generating-random-numbers-without-repetitions – Steven B. Segletes Aug 14 '13 at 14:07
  • My solution to this problem was to do all the random numbers generation in C and write a file for \input to LaTeX. You could generate a pre-randomized lint of names and pull them off one at a time. – John Kormylo Aug 14 '13 at 20:08
  • @JohnKotmylo The thing is that I make a presentation like this (with about 20 questions) once a week, 35 weeks a year for each of my class. Following your idea, I could generate a high number of data in csv file (boring but I would do it once). Then, the "seed" could be the line where to start reading. I wonder though how to achieve this last step easily (csvsimple doesn't seem to allow that). – remjg Aug 14 '13 at 21:23
  • @StevenB.Segletes Thank you for you link, indeed it seems to be what I'm looking for... but I'm must say I don't understand the code that was posted! I will try it tomorrow to see if it's faster to compile. – remjg Aug 14 '13 at 21:31

0 Answers0