I would like to produce quadratic equation with integer coefficients.
Here's my code using pgfmath
.
\documentclass{article}
\usepackage{tikz}
\pgfmathsetseed{\pdfuniformdeviate 10000000}
\begin{document}
$\pgfmathdeclarerandomlist{signe}{{+}{-}}%
\pgfmathrandomitem{\s}{signe}%
\pgfmathparse{random(2)}%
\pgfmathparse{ifthenelse(\pgfmathresult==1,"-"," ")}\pgfmathresult
\pgfmathrandominteger{\a}{1}{6}
\pgfmathparse{ifthenelse(\a==1," x^{2} ","\a x^{2}")}\pgfmathresult % coeff a
\pgfmathdeclarerandomlist{lincoeff}{{}{2}{3}{4}{5}{6}}
\pgfmathrandomitem{\b}{lincoeff}%
\pgfmathrandomitem{\s'}{signe}%
\pgfmathsetmacro{\e}{random(0,6)}
\pgfmathparse{ifthenelse(\e==0," ", " \s' \b x ")}\pgfmathresult % coeff b
\pgfmathrandominteger{\c}{0}{6}
\pgfmathrandomitem{\s''}{signe}%
\pgfmathparse{ifthenelse(\c==0,"","\s'' \c")}\pgfmathresult % coeff c
=0$
\end{document}
It works but it seems to be not a good way, I had some pain with the x-coeficient
and my solution looks complicated.
I tried to use an ifthenelse
inside an other ifthenelse
but without success.
Is there a better way ?
+
or-
I would justrandominteger
between-6
and6
, for example. (If0
is not allowed put it in a loop that is exited when the result is not0
.)