I am working on a system to randomly generate some exercises on unit conversion.
The students get a exercise like
27.89 mm = …… hm
I achieved this whit the use of a random value generator and the ifthen
package. But something is going wrong whit the spacing of this package.
This is the code I use whit one table of how it should be and one table that is randomly generated:
\documentclass{article}
\newcommand{\randFloat}{
\reinitrand[first=0, last=100, counter=var]
\rand\arabic{var}.\rand\arabic{var}
}
\newcommand{\randGrooth}{
\reinitrand[first=1,last=7,counter = grooth]
\rand
\ifthenelse{\arabic{grooth} = 1}{mm}{
\reinitrand[first=1,last=6,counter = test]
\rand
\ifthenelse{\arabic{test} = 1}{cm}{
\reinitrand[first=1,last=5,counter = test]
\rand
\ifthenelse{\arabic{test} = 1}{dm}{
\reinitrand[first=1,last=4,counter = test]
\rand
\ifthenelse{\arabic{test} = 1}{m}{
\reinitrand[first=1,last=3,counter = test]
\rand
\ifthenelse{\arabic{test} = 1}{dam}{
\reinitrand[first=1,last=2,counter = test]
\rand
\ifthenelse{\arabic{test} = 1}{hm}{km}
}
}
}
}
}
}
\usepackage{calc}
\usepackage{ifthen}
\usepackage{lcg}
\begin{document}
\begin{table}
\centering
\begin{tabular}{ll}
44.36 mm =& \hspace*{10 ex} m\\
56.28 dm=& \hspace*{10 ex} km
\end{tabular}
\end{table}
\begin{table}
\centering
\begin{tabular}{ll}
\randFloat \randGrooth =& \hspace*{10 ex} \randGrooth\\
\randFloat \randGrooth =& \hspace*{10 ex} \randGrooth
\end{tabular}
\end{table}
\end{document}
Best Answer
This solution uses
pdftex
primitives, so it needspdflatex
to run. The units are typeset withsiunitx
package, they are organized into an array by means of\csname
.