A number N and a range a to b will be input by the user, with a < b < N.
The program purpose is to generate random sets of positive integers that sum up to N, with each positive integers within the range a and b.
N = 26 a = 1 b = 10
And here are some possible output of the program:
1,1,10,1,1,1,1,10 3,2,1,10,5,5 10,10,6 1,2,3,4,5,6,5
One way to do that is:
Generate 2 y,y within the range
If the y+y > N, start over again.
If the y+y-N < a, start over again
If the y+y-N < b, return the set y, y, N-y-y
Else, generate y[i] within the range
If the y+y+...+y[i]-N < b, return the set y, y, ..., N-y-y-...-y[i]
Else, repeat 5-6
The problem is that the random function is slow. Is there a more efficient way to do this with less number of random?