3

I have tried to create an exam with random questions selected from different files as shown here.

The code I used works but is only randomized on a random basis; i.e. for 1st round it gives a set of questions, no change in 2nd-4th rounds, new order 5th and 6th rounds, no change again for another few compilations.

There are no errors, just randomization fails upon compilation. Maybe, it is just a coincidence. I only use 9 files but they still should have at least 1 change (as per probability theory).

I am using TeXLive v1.17.

Below I have 3 folders named 'Photochem', 'Photophys' and 'Quenching'. In each of these folders I have 3 files named PC1.tex,PC2.tex,PC3.tex; PP1.tex,PP2.tex,PP3.tex; and Quench1.tex, Quench2.tex, Quench3.tex.

Each file just contains the filename as text (just like a Hello World example) so I can see what file is being selected.

Is anyone else able to replicate the scenario and if so, may I have any suggestion how to overcome it?

\documentclass{article}
%\usepackage[paperheight=3.0cm, paperwidth=12.0cm, margin=0.1cm]{geometry}% Simplify image capture

\usepackage{enumitem}
\usepackage{tikz}% Easy way to get all the pgf functions

% The list of topics determines how many questions will be in the quiz
% since it appears that you want one question per topic in a quiz.
% This could be auto generated.
\newcommand*{\ListOfTopics}{%
Photochem,%  MUST have trailing % here
Photophys,%
Quenching%  
}%


% These list of files names from each question can be auto generated
% but for example purposes I am just using the file names as the
% content in the file. The number of questions in each topic do not
% need to be the same.  I would create directories with the topic 
% names and auto generate this based on the directory and file names.

\pgfmathdeclarerandomlist{Photochem}{%
{PC1}%
{PC2}%
{PC3}%
}%
\pgfmathdeclarerandomlist{Photophys}{%
{PP1}%
{PP2}%
{PP3}%
}%
\pgfmathdeclarerandomlist{Quenching}{%
{Quench1}%
{Quench2}%
{Quench3}%
}%



\newcommand*{\NumberOfQuizes}{4}%

\begin{document}
\foreach \QuizNumber in {1,...,\NumberOfQuizes} {%
\clearpage% Start each quiz on a new page
\noindent\textbf{\Large Quiz Number \QuizNumber}%
\begin{enumerate}
\foreach \Topic in \ListOfTopics {%
    % Determine random question to use form list
    \pgfmathrandomitem{\RandomQuestion}{\Topic} 
    % The following should import the file named in \RandomQuestion
    \item Random Question from Topic='\Topic': 
        \textbf{\Large\RandomQuestion}%
}%
\end{enumerate}
}%

\end{document}
Leeser
  • 2,752
  • Do you stick to pgfrandom...? I have written something similar quite a while, perhaps, it can be adapted to your needs? –  Mar 13 '14 at 17:38
  • I am willing to use any methodology at all. There's always more than one way to skin a cat! – Leeser Mar 13 '14 at 17:43
  • Although I prefer living unskinned cats (;-)), I will try tomorrow to reactivate that code. –  Mar 13 '14 at 20:23

1 Answers1

2

The problem is perhaps the random seed, but I did not looked inside the tikz library. In my solution, I am setting the random seed to a value from current time value.

\documentclass{article}
\usepackage{datetime} % Needed for \currentsecond,\currentminute commands
\usepackage{calculator} % Needed for some calc, but perhaps can be done with tikz too
%\usepackage[paperheight=3.0cm, paperwidth=12.0cm, margin=0.1cm]{geometry}% Simplify image capture

\usepackage{enumitem}
\usepackage{tikz}% Easy way to get all the pgf functions

% The list of topics determines how many questions will be in the quiz
% since it appears that you want one question per topic in a quiz.
% This could be auto generated.
\newcommand*{\ListOfTopics}{%
Photochem,%  MUST have trailing % here
Photophys,%
Quenching%  
}%


% These list of files names from each question can be auto generated
% but for example purposes I am just using the file names as the
% content in the file. The number of questions in each topic do not
% need to be the same.  I would create directories with the topic 
% names and auto generate this based on the directory and file names.

\pgfmathdeclarerandomlist{Photochem}{%
{PC1}%
{PC2}%
{PC3}%
}%
\pgfmathdeclarerandomlist{Photophys}{%
{PP1}%
{PP2}%
{PP3}%
}%
\pgfmathdeclarerandomlist{Quenching}{%
{Quench1}%
{Quench2}%
{Quench3}%
}%



\newcommand*{\NumberOfQuizes}{8}%

\begin{document}
\def\TotalSecondsMinute{}
\def\TotalSeconds{}
\MULTIPLY{\currentminute}{60.0}{\TotalSecondsMinute} 
\ADD{\TotalSecondsMinute}{\currentsecond}{\TotalSeconds}
\TotalSeconds
\pgfmathsetseed{\TotalSeconds}% Uses the number of seconds since the hour started


\foreach \QuizNumber in {1,...,\NumberOfQuizes} {%

%\clearpage% Start each quiz on a new page
\noindent\textbf{\Large Quiz Number \QuizNumber}%
\begin{enumerate}
\foreach \Topic in \ListOfTopics {%
    % Determine random question to use form list
    \pgfmathrandomitem{\RandomQuestion}{\Topic} 
    % The following should import the file named in \RandomQuestion
    \item Random Question from Topic='\Topic': 
        \textbf{\Large\RandomQuestion}%
}%
\end{enumerate}
}%

\end{document}

It changes the questions -- does this fit your needs?

EDIT There was a line of unnecessary code -- I removed it.

  • It works better, but in each case Quiz Number 1 always returns PC1 as the random question 1. All others are random! – Leeser Mar 14 '14 at 15:55
  • @Leeser: Yes, you are right -- I will try to figure that out. –  Mar 14 '14 at 15:57
  • I did make the following change \foreach\Quiznumber in {1, 2,...,\NumberOfQuizes} to see if it would make a difference but it didn't. Most likely something small! – Leeser Mar 14 '14 at 17:25