确定骰子卷中显示的数字的频率

bug*_*ixr 5 algorithm probability dice

对于一个游戏,我试图确定某个#将在给定的掷骰子#上出现的频率.我知道......这个问题似乎很奇怪.让我试着用实数来解释它.

因此,对于1个芯片,每个数字的频率将是相同的.1-6将显示相同的次数.

现在2个骰子,事情变得不同了.我想5,6,7将是最频繁滚动的,而频谱两端的数字将显示较少或根本不显示(在1的情况下).我想知道如何计算这个列表并以正确的顺序显示它们,从最常见到较不频繁.

有什么想法吗?


@duffymo - 虽然有一些算法来提出它会非常好.似乎上述方式需要大量的手工采摘和数字放置.如果我的死亡数量是动态的,可以说是10,那么我认为手工操作将是无效的和麻烦的.:)

duf*_*ymo 11

两个骰子有6*6 = 36种组合.

2 = 1 + 1只能出现一次,因此其频率为1/36.3 = 1 + 2或2 + 1,因此其频率为2/36 = 1/18.4 = 1 + 3,2 + 2或3 + 1,因此其频率为3/36 = 1/12.

你可以休息到十二点.

任何步步高玩家都很了解这些.


mqp*_*mqp 5

递归方法的粗略草稿:

public static IEnumerable<KeyValuePair<int, int>> GetFrequenciesByOutcome(int nDice, int nSides)
{
    int maxOutcome = (nDice * nSides);
    Dictionary<int, int> outcomeCounts = new Dictionary<int, int>();
    for(int i = 0; i <= maxOutcome; i++)
        outcomeCounts[i] = 0;

    foreach(int possibleOutcome in GetAllOutcomes(0, nDice, nSides))
        outcomeCounts[possibleOutcome] = outcomeCounts[possibleOutcome] + 1;

    return outcomeCounts.Where(kvp => kvp.Value > 0);
}

private static IEnumerable<int> GetAllOutcomes(int currentTotal, int nDice, int nSides)
{
    if (nDice == 0) yield return currentTotal;
    else
    {
        for (int i = 1; i <= nSides; i++)
            foreach(int outcome in GetAllOutcomes(currentTotal + i, nDice - 1, nSides))
                yield return outcome;
    }
}
Run Code Online (Sandbox Code Playgroud)

除非我弄错了,否则这应该会输出像[键,频率]这样组织的KeyValuePairs。

编辑:仅供参考,运行此命令后,它显示 GetFrequenciesByOutcome(2, 6) 的频率为:

2:1

3:2

4:3

5:4

6:5

7:6

8:5

9:4

10:3

11:2

12:1


Cad*_*oux 5

没有真正的"算法"或模拟必要 - 它是基于De Moivre推导的公式的简单计算:

http://www.mathpages.com/home/kmath093.htm

它不是"钟形曲线"或正态分布.