[Solved] How to generate random sampling in python . with integers. with sum and size given


You can use random.gauss to generate 6 numbers around a mean with a certain standard deviation (closeness) and as per @PatrickArtner suggestion construct the 7th one, e.g. using 3 standard devs from mean:

In []:
import random
vals = [int(random.gauss(341/7, 3)) for _ in range(6)]
vals.append(341 - sum(vals))
vals, sum(vals), sum(vals)/7

Out[]:
([47, 47, 48, 48, 54, 50, 47], 341, 48.714285714285715)

solved How to generate random sampling in python . with integers. with sum and size given