How to make 5 random numbers with sum of 100

前端 未结 8 1632
旧巷少年郎
旧巷少年郎 2020-12-03 13:17

do you know a way to split an integer into say... 5 groups. Each group total must be at random but the total of them must equal a fixed number.

for example I have \"

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 13:21

    Pick 4 random numbers, each around an average of 20 (with distribution of e.g. around 40% of 20, i.e. 8). Add a fifth number such that the total is 100.

    In response to several other answers here, in fact the last number cannot be random, because the sum is fixed. As an explanation, in below image, there are only 4 points (smaller ticks) that can be randomly choosen, represented accumulatively with each adding a random number around the mean of all (total/n, 20) to have a sum of 100. The result is 5 spacings, representing the 5 random numbers you are looking for.

    only 4 random point between 0 and 100

提交回复
热议问题