Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Random enumeration in LaTex

1,730 views
Skip to first unread message

TCL

unread,
May 13, 2010, 4:00:32 PM5/13/10
to
Is it possible to tell LaTex to randomly enumerate a list?

Like


\begin{enumerate}[random]


\item .....
\item ....


\end{enumerate} [random]


This should come in handy for teachers making up multiple choice
exams.


Marco Daniel

unread,
May 13, 2010, 4:59:23 PM5/13/10
to
Hi,

you can combine the list environment with the package lcg.

regards
Marco

schrieb TCL:

TCL

unread,
May 13, 2010, 6:56:09 PM5/13/10
to
On May 13, 4:59 pm, Marco Daniel <marcodaniel1...@googlemail.com>
wrote:
> > exams.- Hide quoted text -
>
> - Show quoted text -

I installed the package. But what is the command? The command I show
above \begin{enumerate}[random]
does not work.

Thank you very much.

Martin Heller

unread,
May 13, 2010, 7:32:06 PM5/13/10
to
On 2010-05-14 00:56, TCL wrote:

>>> This should come in handy for teachers making up multiple choice
>>> exams.- Hide quoted text -
>>

There are multiple packages for creating exams on ctan
http://www.ctan.org/pkg/examdesign
http://www.ctan.org/pkg/exam
http://www.ctan.org/pkg/exams
http://www.ctan.org/pkg/exerquiz

the latter is part of the AcroTeX education bundle
http://ctan.org/pkg/acrotex
that allows you to make interactive tests, games and quizzes.

> I installed the package. But what is the command? The command I show
> above \begin{enumerate}[random]
> does not work.
>
> Thank you very much.

I think you need to do something along the lines of:

\documentclass{article}
\usepackage{lcg}

\begin{document}

\reinitrand[first=1, last=3, counter=die]
\begin{itemize}
\item[\rand\arabic{die}.] Foo.
\item[\rand\arabic{die}.] Bar.
\item[\rand\arabic{die}.] Baz.
\end{itemize}

\end{document}

José Carlos Santos

unread,
May 14, 2010, 2:50:04 AM5/14/10
to
On 13-05-2010 23:56, TCL wrote:

> I installed the package. But what is the command? The command I show
> above \begin{enumerate}[random]
> does not work.

Try this:

\documentclass{article}
\usepackage[first=1,last=6]{lcg}
\begin{document}
\begin{enumerate}
\item[\rand\arabic{rand}.] Something
\item[\rand\arabic{rand}.] Something else
\item[\rand\arabic{rand}.] And still something else
\end{enumerate}
\end{document}

Best regards,

Jose Carlos Santos

TCL

unread,
May 14, 2010, 10:47:27 AM5/14/10
to
On May 13, 7:32 pm, Martin Heller <mr_hel...@yahoo.dk> wrote:
> On 2010-05-14 00:56, TCL wrote:
>
> >>> This should come in handy for teachers making up multiple choice
> >>> exams.- Hide quoted text -
>
> There are multiple packages for creating exams on ctanhttp://www.ctan.org/pkg/examdesignhttp://www.ctan.org/pkg/examhttp://www.ctan.org/pkg/examshttp://www.ctan.org/pkg/exerquiz
>
> the latter is part of the AcroTeX education bundlehttp://ctan.org/pkg/acrotex

> that allows you to make interactive tests, games and quizzes.
>
> > I installed the package. But what is the command? The command I show
> > above  \begin{enumerate}[random]
> > does not work.
>
> > Thank you very much.
>
> I think you need to do something along the lines of:
>
> \documentclass{article}
> \usepackage{lcg}
>
> \begin{document}
>
> \reinitrand[first=1, last=3, counter=die]
>   \begin{itemize}
>    \item[\rand\arabic{die}.] Foo.
>    \item[\rand\arabic{die}.] Bar.
>    \item[\rand\arabic{die}.] Baz.
>   \end{itemize}
>
> \end{document}

This does not work. The result it produces is a random order of the
number but not the content of the number: e.g. 3. Foo 1. Bar 2.
Baz
What one intended should be e.g. 1. Bar 2. Baz 3. Foo

TCL

unread,
May 14, 2010, 10:50:28 AM5/14/10
to

This does not work. The result it produces is a random order of the
number but not the content of the number: e.g. 5. Something 1.
Something else 2. And still something else
What one intended should be e.g. 1. Something else 2. And still
something else 3. Something

ma...@mendelu.cz

unread,
May 14, 2010, 8:10:22 PM5/14/10
to
On 14 kvě, 01:32, Martin Heller <mr_hel...@yahoo.dk> wrote:
> On 2010-05-14 00:56, TCL wrote:
>
> >>> This should come in handy for teachers making up multiple choice
> >>> exams.- Hide quoted text -
>
> There are multiple packages for creating exams on ctanhttp://www.ctan.org/pkg/examdesignhttp://www.ctan.org/pkg/examhttp://www.ctan.org/pkg/examshttp://www.ctan.org/pkg/exerquiz
>
> the latter is part of the AcroTeX education bundlehttp://ctan.org/pkg/acrotex

> that allows you to make interactive tests, games and quizzes.
>

AcroTeX education bundle has also forpaper option and allowrandomize -
this option makes what you want. Just try it.

If you do not want to use this bundle, you need something like this
(use lualatex to compile):

\documentclass{article}

\begin{document}

\def\saveitem#1#2{\expandafter\def\csname option#1\endcsname{#2}}
\def\useitem{\item \def\temp{\directlua{tex.print(math.random(1,3))}}
\csname option\temp \endcsname}
\begin{itemize}
\saveitem1{first}
\saveitem2{second}
\saveitem3{third}
\useitem
\useitem
\useitem
\end{itemize}

\end{document}


Far from perfect, since the same answer may appear multiple times -
you need a random permuation rather than random numbers. I have seen a
similar example with luatex, but cannot find it just now. Needs
programming, but generaly this is the way.


Robert

Oliver Corff

unread,
May 15, 2010, 3:34:28 AM5/15/10
to
TCL <tl...@cox.net> wrote:

Hi,

I just think of a possible solution which helps you randomize the
/order/ of your items rather than their enumeration.

The following code is untested and certainly contains errors, but
perhaps you get the idea.

You should separate answers and numbering. Store the answers in a
structure separate from your itemized list.

\documentclass{article}
\usepackage[first=1,last=5]{lcg}
\newcommand{\MyChoice}[1]{\ifcase #1
\or Some item
\or Another item
\or Yet another item
\or Again another item
\or A fifth item
\fi}

\begin{document}
\begin{enumerate}
\item \MyChoice{\rand\arabic{rand}}
\item \MyChoice{\rand\arabic{rand}}
\item \MyChoice{\rand\arabic{rand}}
\item \MyChoice{\rand\arabic{rand}}
\item \MyChoice{\rand\arabic{rand}}
\end{enumerate}
\end{document}

For more multiple-choice questions, you can \renewcommand{\MyChoice}.

Hth,

Oliver.

--
Dr. Oliver Corff e-mail: co...@zedat.fu-berlin.de

TCL

unread,
May 15, 2010, 9:18:11 AM5/15/10
to
On May 15, 3:34 am, Oliver Corff <co...@samoa.zedat.fu-berlin.de>
wrote:
> TCL <tl...@cox.net> wrote:

No. That does not work. It produces the following:

1. =5532
2.
3.
4.
5.

The 5532 changes every time I run it -- that is due to randomness. But
of course this does not help.

ma...@mendelu.cz

unread,
May 15, 2010, 12:00:27 PM5/15/10
to

For solution to your problem look at http://www.math.uakron.edu/~dpstory/acrotex/aeb_man.pdf
page 115 (randomizing the multiple choices). Does this help.

Robert

Oliver Corff

unread,
May 15, 2010, 12:58:14 PM5/15/10
to
: > Hi,

: >
: > I just think of a possible solution which helps you randomize the
: > /order/ of your items rather than their enumeration.
: >

As I said:

: > The following code is untested and certainly contains errors, but


: > perhaps you get the idea.
: >
: > You should separate answers and numbering. Store the answers in a
: > structure separate from your itemized list.
: >
: > \documentclass{article}
: > \usepackage[first=1,last=5]{lcg}
: > \newcommand{\MyChoice}[1]{\ifcase #1
: > � � � � \or Some item
: > � � � � \or Another item
: > � � � � \or Yet another item
: > � � � � \or Again another item
: > � � � � \or A fifth item
: > � � \fi}
: >
: > \begin{document}
: > \begin{enumerate}
: > � � \item \MyChoice{\rand\arabic{rand}}
: > � � \item \MyChoice{\rand\arabic{rand}}
: > � � \item \MyChoice{\rand\arabic{rand}}
: > � � \item \MyChoice{\rand\arabic{rand}}
: > � � \item \MyChoice{\rand\arabic{rand}}
: > \end{enumerate}
: > \end{document}

: >

: No. That does not work. It produces the following:

: 1. =5532
: 2.
: 3.
: 4.
: 5.

: The 5532 changes every time I run it -- that is due to randomness. But
: of course this does not help.

As I said, the code is untested. Change it as follows:
: > � � \item \MyChoice{\rand\arabic{rand}}
becomes:
\item \rand\MyChoice{\arabic{rand}}

The argument to \MyChoice must be a plain digit, it was my mistake
to put the \rand call into the argument, too. If you call \rand before
invoking \MyChoice, the example works.

ma...@mendelu.cz

unread,
May 15, 2010, 2:12:38 PM5/15/10
to
On 15 kvě, 18:58, Oliver Corff <co...@samoa.zedat.fu-berlin.de> wrote:
>
> The argument to \MyChoice must be a plain digit, it was my mistake
> to put the \rand call into the argument, too. If you call \rand before
> invoking \MyChoice, the example works.

Hi, it compiles but does not work properly - some items are listed two
times and some are missing.

Robert


btw: I tested this:

\documentclass{article}
\usepackage[first=1,last=5]{lcg}
\newcommand{\MyChoice}[1]{\ifcase #1
\or Some item
\or Another item
\or Yet another item
\or Again another item
\or A fifth item
\fi}

\begin{document}
\begin{enumerate}
\item \rand\MyChoice{\arabic{rand}}


\item \rand\MyChoice{\arabic{rand}}
\item \rand\MyChoice{\arabic{rand}}
\item \rand\MyChoice{\arabic{rand}}
\item \rand\MyChoice{\arabic{rand}}

\end{enumerate}
\end{document}

Oliver Corff

unread,
May 15, 2010, 2:51:21 PM5/15/10
to
ma...@mendelu.cz <ma...@mendelu.cz> wrote:

: On 15 kv?, 18:58, Oliver Corff <co...@samoa.zedat.fu-berlin.de> wrote:
: >
: > The argument to \MyChoice must be a plain digit, it was my mistake
: > to put the \rand call into the argument, too. If you call \rand before
: > invoking \MyChoice, the example works.

: Hi, it compiles but does not work properly - some items are listed two
: times and some are missing.

Sure. The example lacks a mechanism to check which numbers have been called
before, and it doesn't check which ones it failed to call. The example
was solely intended to demonstrate how to separate item numbering from
the order of items. Same with the luatex example.

So it is perhaps best not to re-invent the wheel but to use proven
solutions as in the packages you recommended.

0 new messages