I am faced with the following programming problem. I need to generate n (a, b) tuples for which the sum of all a‘s is a given A and sum of all b‘s is a given B and for each tuple the ratio of a / b is in the range (c_min, c_max). A / B is within the same range, too. I am also trying to make sure there is no bias in the result other than what is introduced by the constraints and the a / b values are more-or-less uniformly distributed in the given range.
Some clarifications and meta-constraints:
A,B,c_min, andc_maxare given.- The ratio
A / Bis in the(c_min, c_max)range. This has to be so if the problem is to have a solution given the other constraints. - a and b are
>0and non-integer.
I am trying to implement this in Python but ideas in any language (English included) are much appreciated.
Start by generating as many identical tuples, n, as you need:
(A/n, B/n)Now pick two tuples at random. Make a random change to the
avalue of one, and a compensating change to theavalue of the other, keeping everything within the given constraints. Put the two tuples back.Now pick another random pair. This times twiddle with the
bvalues.Lather, rinse repeat.