0

Let's say I have a number m (it will be integer, usually 1) and I want to split m into n random numbers, which have the sum m. I want to make a distribution which will be random, but will be close (doesn't have to be really close) to uniform distribution.
I have this

pieces = []
for i in range(n-1):
    pieces.append(random.uniform(0,m-sum(pieces)))
pieces.append(m-sum(pieces))

The problem is, that the first number is usually really high compared to the rest of the numbers. When I tried it for m = 1 and let's say n=10, the first number was close to 0,5 and the last number was close to like 0,001 (or something like that), which is not a problem, but the problem is, that the first number is on average really big compared to all of the other numbers.

My question is: Is there some kind of way to do this, so the numbers are closer? There can be a big difference between biggest and smallest number, but I want it to feel more uniform, if that makes sense.

  • You could try generating bins of equal size and then drawing numbers from bins in a manner to approximate a normal distribution – Tim Stack Apr 19 '22 at 07:43
  • Or you can just shuffle the results after generating them, if you only care about position, not magnitude. – Grekkq Apr 19 '22 at 07:47

0 Answers0