About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Account
Latest news 2024-10-15: New blog post: Tales for Our Times Book Launch.

Random selection with pgfmath.sty and probsoln.sty

\documentclass{article}

\usepackage{pgfmath}
\usepackage{probsoln}

% set random seed
\pgfmathsetseed{\year}

\begin{defproblem}{easy.diff}%
  \ifundef\easydiffcoeff
  {%
    \pgfmathrandominteger{\easydiffcoeff}{2}{10}% generate random coefficient
    \global\let\easydiffcoeff\easydiffcoeff % make it global
  }
  {}% already been defined
  \begin{onlyproblem}
  % question
  Differentiate with respect to $x$:
  \[
    y = \sin(\easydiffcoeff x)
  \]
  \end{onlyproblem}
  \begin{onlysolution}
  % solution
  $ y' = \easydiffcoeff\cos(\easydiffcoeff x) $
  \end{onlysolution}
\end{defproblem}

\begin{document}

\section{Questions}

\begin{enumerate}
\foreachproblem{\item\thisproblem}
\end{enumerate}

\showanswers
\section{Solutions}
\begin{enumerate}
\foreachsolution{\item\thisproblem}
\end{enumerate}

\end{document}


Download probsoln-rand.tex or probsoln-rand.pdf.

© 2015 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Cookies Site Map FAQs