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



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).


\usepackage[margin=1.5cm, landscape]{geometry}




\_\_\_\_\_\_\_\_ \(\times\) \_ \_ \_ \_ \(=\product\) \hspace{4cm} \(\m\times\n=\product\)


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



\begin{center} \Huge Integer Pairs\end{center}





  • 1
    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
  • 3
    It's better to avoid links in questions because they not be around in a few years time when someone comes across this question. Local code also make it more likely that people will look at your question, as many people won't follow links. Similarly, if you don't close off your question by selecting the best answer people will stop answering your questions too! (FYI, only about 1/3 of your questions have selected answers.) – user30471 Nov 11 '16 at 6:57
  • 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


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


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.