随机选择文件问题

随机选择文件问题

我尝试创建一个exam从不同文件中选择的随机问题,如下所示这里

我使用的代码可以工作,但只是在随机基础上随机化;例如,第一轮它会给出一组问题,第二至第四轮没有变化,第五轮和第六轮有新的顺序,另外几次编译也不会再有变化。

没有错误,只是编译时随机化失败。也许,这只是一个巧合。我只使用了 9 个文件,但它们仍然应该至少有 1 个变化(根据概率论)。

我在用TeXLive v1.17

下面我有 3 个文件夹,分别名为“Photochem”、“Photophys”和“Quenching”。在每个文件夹中,我都有 3 个文件,分别名为PC1.texPC2.texPC3.texPP1.texPP2.texPP3.tex; 和Quench1.texQuench2.texQuench3.tex

每个文件只包含文件名作为文本(就像一个Hello World例子),所以我可以看到正在选择哪个文件。

还有其他人能够复制这种情况吗?如果可以,我可以提出一些建议来克服它吗?

\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}

答案1

问题可能出在随机种子上,但我没有查看tikz库内部。在我的解决方案中,我将随机种子设置为当前时间值中的一个值。

\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}

它改变了问题——这符合您的需要吗?

编辑 有一行不必要的代码--我将其删除了。

相关内容