I have found an answer (this) showing how to generate random numbers that add up to a number, but I need those numbers to be less that 100. How might I go about this?
Asked
Active
Viewed 689 times
0
-
Please make clear what does it mean "random" in this case. A small discussion. In order to get a (uniformly) random number from $0$ to $9$ one has to insure that each digit is equally probable. Now, in our case, should we generate a random partition of $180$ with pieces $\le 100$ so that each such partition has the same chance? Does this matter? (In loc. cit. this was the point of the answer...) A way to "do something" is to generate random partitions of $180$ till all parts are $\le 100$. Please also show the own thoughts, the answerers will type more sentences... – dan_fulea Oct 25 '18 at 16:45
-
The answer you linked answers your question. The "randfixedsum" routine allows you to place bounds on the random numbers. – eyeballfrog Oct 25 '18 at 17:04
1 Answers
0
The problem is when you slice cube $[0,100]^5$ with hyperplane $\sum X_i=180$, you will no longer get a simplex, but instead get a truncated simplex. The most practical thing to do here is to use the algorithm from your link to generate the 5 numbers that add up to 180 until all of them less than 100. The probability to reject the point will be $$ p = 5\left(\frac{180-100}{180}\right)^4 = 0.195 $$ so your algorithm will be slower by 25% on average, which is not that bad.
Vasily Mitch
- 10,129