How can I simulate the frequency of each face for N die rolls? [duplicate]

I want to simulate a fair die roll N times without actually rolling a die.
To be clear, I want to achieve something like this:

N = 1000
"1" showed up 185 times
"2" showed up 162 times
"3" showed up 158 times
"4" showed up 148 times
"5" showed up 182 times
"6" showed up 165 times

I can say that, for example, the number 1 shows up

random_binomial_distribution(N = 1000, probability = (1/6))

times. But I can’t apply this for all faces, as the sum of all these results will likely not equal 1000.

How can I simulate the frequency of each face for N rolls without iterating through every roll?


The frequencies for the different faces aren’t independent, since they have to sum to N. However, instead of iterating over the dice, you can iterate over the number of faces, which doesn’t increase with N:

  1. Simulate occurrences of 1, n_1, as Binomial, with N trials and success probability 1/6.
  2. Simulate occurrences of 2, n_2, as Binomial, with N – n_1 trials and success probability 1/5.
  3. Simulate occurrences of 3, n_3, as Binomial, with N – n_1 – n_2 trials and success probability 1/4.

And so on, until you simulate the occurrences of 6 with a success probability of 1, using up all the remaining rolls.

Source : Link , Question Author : Stack Danny , Answer Author : Accidental Statistician

Leave a Comment