My interpretation is the same as that of rcollyer's – you want to randomly generate 25 pairs of rational numbers and with the 4 choices being the result of {+,-,*,/}
on each pair, but in a shuffled order. The question is then a single randomly chosen operation on the corresponding pair of fractions.
In order to do that, I strongly suggest reading the answer to Sasha's question on generating uniformly distributed rational numbers with an upper bound on the denominator. Specifically, the function RandomFarey
, which is Sasha's implementation of btilly's answer. I suggest this instead of the more intuitive Rationalize[RandomReal[...]]
approach, because if you're setting a homework for fractions, it's probably for an elementary/middle school class, and you might not want any arbitrary rational number that the obvious approach might throw up (e.g., {273/391, 193/239}
, which probably might be a bit too much, depending on the level).
Now that we have a generating function for the rational numbers, all that needs to be done is generating them up, creating the answer choices, shuffling, and creating a random set of questions and laying them out neatly. Here's one approach of doing that.
makeHomework[n_Integer, denominator_Integer] :=
Module[{rationalPairs = RandomFarey[denominator, 2 n]~Partition~2,
operators = {Plus, Subtract, Times, Divide},
randomOp := RandomChoice[{"+", "-", "\[Times]", "\[Divide]"}],
choiceList, questionList},
choiceList = Outer[Apply, operators, rationalPairs, 1];
questionList = #1 <> randomOp <> #2 <> "=" & @@@
Map[ToString[# // TraditionalForm] &, rationalPairs, {2}];
Grid[Transpose@{questionList,
Row@MapThread[Labeled, {#, {"(a)", "(b)", "(c)", "(d)"}}] & /@
Transpose@choiceList},
Spacings -> {0, 1}]
]
For example, evaluating makeHomework[5, 10]
gives:

This probably takes you 90% of the way there. I'm really in a rush, so there are a few things I have not done, but I hope that you or someone else can address it. They're mostly trivial.
- I don't account for integers. These will mess up the layout (that one will be a little off the line), if the generator were to throw one up.
- I forgot the serial number
- The label sizes should be smaller (or conversely, the numbers should be bigger)
- Other frills and prettifications