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 = 26a = 1b = 10And here are some possible output of the program:1,1,10,1,1,1,1,103,2,1,10,5,510,10,61,2,3,4,5,6,5One way to do that is:Generate 2 y[0],y[1] within the rangeIf the y[0]+y[1] > N, start over again.If the y[0]+y[1]-N < a, start over againIf 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 rangeIf 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-6The problem is that the random function is slow. Is there a more efficient way to do this with less number of random?
How to generate a random bag of positive integers that sum up to an input number?
algorithms;random