![随机数及其进一步用途](https://linux22.com/image/457086/%E9%9A%8F%E6%9C%BA%E6%95%B0%E5%8F%8A%E5%85%B6%E8%BF%9B%E4%B8%80%E6%AD%A5%E7%94%A8%E9%80%94.png)
我正在为我的学生设计随机练习表。我可以使用以下代码获取不重复的随机数\includegraphics 中无重复的随机数。现在我想使用随机数来创建唯一的表格。例如。我有 20 个可能的 mc 问题,我想为每个学生使用 5 个不同的问题。每个问题都外包在 .tex 文件中。
例子:
- 随机数 1 -> \input{1.tex}
- 随机数 3 -> \input{3.tex}
- 随机数 8 -> \input{8.tex}
每个 X.tex 文件包含一个表格行,如下所示
a & b & c & d \\
现在我的问题是,如果我使用表格环境,会出现以下错误代码。我不明白缺少的} 在哪里。
! Extra }, or forgotten \endgroup. <template> \unskip \hfil } \hskip \tabcolsep \endtemplate l.56 \randomincludegraphics{total}?
这是我的 MWE:
\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\begin{document}
\makeatletter
\def\declarenumlist#1#2#3{%
\@ifundefined{c@#1@listcount}{\newcounter{#1@listcount}}{}%
\setcounter{#1@listcount}{1}%
\begingroup
\count@=#2\relax
\def\x{}%
\loop
\edef\x{\x{\the\count@}}%
\global\expandafter\let\csname#1@\number\count@ @used\endcsname\relax
\ifnum\count@<#3\relax
\advance\count@\@ne
\stepcounter{#1@listcount}%
\repeat
\edef\x{\endgroup
\noexpand\pgfmathdeclarerandomlist{#1}{\x}%
}\x
\expandafter\mathchardef\csname #1@number\endcsname\value{#1@listcount}%
\setcounter{#1@listcount}{0}%
}
\newcommand{\pgfmathuniquerandomitem}[2]{%
\pgfmathrandomitem#1{#2}%
\ifnum\value{#2@listcount}=\@nameuse{#2@number}%
\@latex@warning{List #2 exhausted}%
\else
\@ifundefined{#2@#1@used}%
{\stepcounter{#2@listcount}\global\@namedef{#2@#1@used}{used}}%
{\pgfmathuniquerandomitem#1{#2}}%
\fi
}
\makeatother
\newcommand{\randomincludegraphics}[2][]{%
\begingroup
\pgfmathuniquerandomitem\z{#2}%
% Uncomment the following line for the production version
\input{\z.tex}
% and remove the following line
% I want to include \texttt{\z.pdf} with options ``\texttt{#1}''
\endgroup
}
%I want 2 numbers because I have 2 possible rows
\begin{tabular}{cccc}
\declarenumlist{total}{1}{2}
\randomincludegraphics{total}
\randomincludegraphics{total}
\end{tabular}
%content of 1.tex
% a & b & c & d \\
% content of 2.tex
% e & f & g & h \\
\end{document}