I'm trying to get a random distribution of N integers with total sum equal to K.
numbers = np.array(range(N))
for n in range(N):
prob[n] = rd.randrange(10000)
sum = numpy.sum(prob)
prob = (prob / sum * K).astype(int)
The problem is that the result is not exactly equal to N because of float number approximation. For example N = 100 will yield a a total of about 95.
What is a pythonic solution to this problem?