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.
For example,
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[0],y[1] within the range
If the y[0]+y[1] > N, start over again.
If the y[0]+y[1]-N < a, start over again
If the y[0]+y[1]-N < b, return the set y[0], y[1], N-y[0]-y[1]
Else, generate y[i] within the range
If the y[0]+y[1]+...+y[i]-N < b, return the set y[0], y[1], ..., N-y[0]-y[1]-...-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?