Is it possible to generate $n$ random samples, and always ensure that $n$ samples are generated?
eg For $n=5$:
n=5; {n1, n2, n3, n4, n5} = (While[Total[set = Reverse@Sort@Round
[(tmp = RandomInteger[100, n])/Total@tmp 100]] != 100]; set);
s = Reverse[Sort[{n1, n2, n3, n4, n5}]];
a = rs[[1]]; b = s[[2]]; c = s[[3]]; d = s[[4]]; e = s[[5]];
PieChart[{a, b, c, d, e}, ImageSize -> 200,
ChartLabels -> {Style[StringForm["A:``%", a], 10],
Style[StringForm["B:``%", b], 10],
Style[StringForm["C:``%", c], 10],
Style[StringForm["D:``%", d], 10],
Style[StringForm["E:``%", e], 10]}]
is ok, but for large enough $n$ the numbers are often "used up" before the last few get a chance to sample (so, in the example of the above pie chart, "E" often doesn't feature).
Is it possible to avoid the samples reaching $0$ before last $n$ is reached? (Obviously, by the time $n=100$, each sample should have value of $1$.)
RandomSample[IntegerPartitions[100, 5], 1]
. However, do take care asIntegerPartitions
can blow up extremely fast and fill up all of your memory (potentially crashing your kernel) if you're not cautious. $\endgroup$Total[list]==100
andMin[list]==1
? $\endgroup$