Note that there are some explanatory texts on larger screens.

plurals
  1. POAvoiding bias in randomly generated subtraction problems
    text
    copied!<p>I'm writing a Python script to generate problems for mental arithmetic drills. The addition and multiplication ones were easy, but I'm running into trouble trying to generate unbiased problems for the subtraction ones.</p> <p>I want to be able to specify a minimum and maximum value that the minuend (first number) will be -- e.g., for two-digit subtraction it should be between 20 and 99. The subtrahend should also have a range option (11-99, say). The answer needs to be positive and preferably also bounded by a minimum of, say, 10 for this situation.</p> <p>So:</p> <ul> <li>20 &lt; Minuend &lt; 99</li> <li>11 &lt; Subtrahend &lt; 99</li> <li>Answer = Minuend - Subtrahend</li> <li>Answer >= 10</li> </ul> <p>All the numeric values should be used as variables, of course.</p> <p>I have these conditions met as follows:</p> <pre><code>ansMin, ansMax = 10, 99 subtrahendMin, minuendMax = 11,99 # the other max and min did not seem to be necessary here, # and two ranges was the way I had the program set up answer = randint(ansMin, ansMax) subtrahend = randint(subtrahendMin, minuendMax - answer) minuend = answer + subtrahend # rearranged subtraction equation </code></pre> <p>The problem here is that the minuend values wind up being nearly all over 50 because the answer and subtrahend were generated first and added together, and only the section of them that were both in the bottom 25% of the range will get the result below 50%. (Edit: that's not strictly true -- for instance, bottom 1% plus bottom 49% would work, and percentages are a bad way of describing it anyway, but I think the idea is clear.)</p> <p>I also considered trying generating the minuend and subtrahend values both entirely randomly, then throwing out the answer if it didn't match the criteria (namely, that the minuend be greater than the subtrahend by a value at least greater than the answerMin and that they both be within the criteria listed above), but I figured that would result in a similar bias.</p> <p>I don't care about it being <em>perfectly</em> even, but this is too far off. I'd like the minuend values to be fully random across the allowable range, and the subtrahend values random across the range allowed by the minuends (if I'm thinking about it right, this will be biased in favor of lower ones). I don't think I really care about the distribution of the answers (as long as it's not ridiculously biased). Is there a better way to calculate this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload