# Somewhat(?) Random Numbers?

I'm making an built with random numbers, that is effectively guessing and checking to solve systems such as:

mn=-10

m+n=3

where m and n are random integers.

Strangely, I notice no cases where m+n=0, except when m=n=0. I've recompiled quite a few times and still haven't found a single case.

Why? Is the random number generation not as random as I thought?

Here is the code, which generates both the exercises (first and third columns) as well as the and the solutions (second and fourth columns).

\documentclass{article}

\usepackage[margin=1.5cm, landscape]{geometry}
\usepackage{ifthen}
\usepackage{multicol}
\setlength{\columnsep}{1.5cm}
\usepackage{pgf}
\usepackage{pgffor}

\setlength{\parindent}{0pt}

\pgfmathsetseed{\number\pdfrandomseed}

\newcommand{\InitVariables}
{
\pgfmathsetmacro{\m}{int(random(0,5)-5)}
\pgfmathsetmacro{\n}{int(random(0,5)-5)}
\pgfmathsetmacro{\sum}{int(\m+\n)}
\pgfmathsetmacro{\product}{int(\m*\n)}
\pgfmathtruncatemacro{\Structure}{random(1,4)}
}

\newcommand{\onequestion}
{
\large
\InitVariables
\_\_\_\_\_\_\_\_ $$\times$$ \_ \_ \_ \_ $$=\product$$ \hspace{4cm} $$\m\times\n=\product$$

\vspace{0.8cm}

\_\_\_\_\_\_\_\_ $$+$$ \_ \_ \_ \_ \ $$=\sum$$ \hspace{4cm} $$\m+\n=\sum$$

\vspace{1.6cm}
}

\pagestyle{empty}

\newcommand{\onepage}
{
\begin{center} \Huge Integer Pairs\end{center}
\vspace{0.5cm}

\begin{multicols}{2}
\onequestion
\onequestion
\onequestion
\onequestion
\onequestion
\onequestion
\onequestion
\onequestion
\onequestion
\onequestion
\end{multicols}
\pagebreak
}

\begin{document}

\onepage

\onepage

\end{document}

• Can you give us some code to work from? Currently we have to randomly guess what you are doing. Certainly, if one of your equations is m+n=3 then you should never get m+n=0! :) – user30471 Nov 11 '16 at 6:52
• There is a link in the original post that has all the code. Also, I just updated the post to make it a bit clearer. – WeCanLearnAnything Nov 11 '16 at 6:53
• RE: Closing off questions. I just gave out a bunch of check marks to prior threads. I hope the authors notice! I wish I had given those check marks earlier. – WeCanLearnAnything Nov 11 '16 at 7:16
• you are declaring m and n to be random integers in the range -5 to 0 so clearly you are not going to get m + n = 0 unless m=n=0 – David Carlisle Nov 11 '16 at 13:42

you are declaring m and n to be random integers in the range -5 to 0 so clearly you are not going to get m + n = 0 unless m=n=0

perhaps you intended

 \pgfmathsetmacro{\m}{int(random(0,10)-5)}
\pgfmathsetmacro{\n}{int(random(0,10)-5)}


so they are in the range -5 to 5 or if (as in your previous question) you want to avoid 0 then

 \pgfmathsetmacro{\m}{int(random(1,5)}
\pgfmathsetmacro{\n}{int(random(1,5)}


so they are in the range 1 to 5, and then have additional random 0 1 random variable to decide the sign

• Yes, this is it... I'm going to try to fix this now. Thanks! Also, is there any update on why \pgfmathsetmacro{\m}{int(random(-5,5)} does not work well? This is the bug I was talking about in a prior thread. – WeCanLearnAnything Nov 11 '16 at 15:55