I think that you are trying to get everything to have exact values that have only one or two decimal places, and I understand why that would be nice. But you could allow for some of these things to have more decimal places, and then rely on rounding for presentation and error tolerance for answer checking.
So you could have:
$a = Currency(random(4,15,0.1));
do{$b = Currency(random(4,15,0.1));} until ($b!=$a);
$x = random(1,50,1);
$y = random(1,50,1);
$n = $x+$y;
$m = ($a*$x+$b*$y)/$n;
And yes, $m might end up not having a short decimal presentation. But $m is a Currency object, so already it will display only down to the cent. So in the exercise statement that you have, it will not show a distracting number of decimal places:
Julia and her husband own a coffee shop. They experimented with mixing a City Roast Colombian coffee that cost [$a] per pound with French Roast Colombian coffee that cost [$b] per pound to make a [$n]-pound blend. Their blend should cost them [$m] per pound. How much of each type of coffee should they buy?
Julia and her husband should mix [________]{$x} pound of the city Roast Colombian coffee, and [________]{$y} pound of the French Roast Colombian coffee to make [$n]-pound blend.
Then with answer checking, the student may do work using that rounded value of $m, and so they might not find $x and $y exactly as they were originally crated. But the error tolerance should make that OK. As long as they enter something within ±0.1% of the actual values of $x and $y, they will get credit under the default error tolerance. If you find that in practice that error tolerance is not enough, you can change it.
Alternatively, you can get those conditions you would like with some careful randomization. I came up with the following, but I would not recommend this approach unless you have time to work these things out carefully:
$a = Currency(random(4,15,0.1));
$x = random(20,40,1);
$y = $x + list_random(-10..-5,5..10);
$m = ($a + $y*random(1,5,1)/100);
$b = $m + ($m - $a)*$x/$y;
$n = $x + $y;
This leaves $x and $y distinct integers that are not too close to each other.
And it leaves $a < $m < $b with each of them Currency objects. And they each have no more than two decimal places. This is true for $b because $y divides into ($m - $a) leaving something with at most 2 decimal places.
The relation m = (ax + by)/(x + y) is true because $b is explicitly defined that way at the end.
So you could have:
$a = Currency(random(4,15,0.1));
do{$b = Currency(random(4,15,0.1));} until ($b!=$a);
$x = random(1,50,1);
$y = random(1,50,1);
$n = $x+$y;
$m = ($a*$x+$b*$y)/$n;
And yes, $m might end up not having a short decimal presentation. But $m is a Currency object, so already it will display only down to the cent. So in the exercise statement that you have, it will not show a distracting number of decimal places:
Julia and her husband own a coffee shop. They experimented with mixing a City Roast Colombian coffee that cost [$a] per pound with French Roast Colombian coffee that cost [$b] per pound to make a [$n]-pound blend. Their blend should cost them [$m] per pound. How much of each type of coffee should they buy?
Julia and her husband should mix [________]{$x} pound of the city Roast Colombian coffee, and [________]{$y} pound of the French Roast Colombian coffee to make [$n]-pound blend.
Then with answer checking, the student may do work using that rounded value of $m, and so they might not find $x and $y exactly as they were originally crated. But the error tolerance should make that OK. As long as they enter something within ±0.1% of the actual values of $x and $y, they will get credit under the default error tolerance. If you find that in practice that error tolerance is not enough, you can change it.
Alternatively, you can get those conditions you would like with some careful randomization. I came up with the following, but I would not recommend this approach unless you have time to work these things out carefully:
$a = Currency(random(4,15,0.1));
$x = random(20,40,1);
$y = $x + list_random(-10..-5,5..10);
$m = ($a + $y*random(1,5,1)/100);
$b = $m + ($m - $a)*$x/$y;
$n = $x + $y;
This leaves $x and $y distinct integers that are not too close to each other.
And it leaves $a < $m < $b with each of them Currency objects. And they each have no more than two decimal places. This is true for $b because $y divides into ($m - $a) leaving something with at most 2 decimal places.
The relation m = (ax + by)/(x + y) is true because $b is explicitly defined that way at the end.