# 离散均匀分布

离散均匀分布是一种概率分布：它把相同的概率 \( 1/n \) 赋予 \( n \) 个互不相同的有限取值中的每一个，而把零概率赋予其他所有取值。<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup> 它描述的是结果构成一张有限清单、且各结果等可能的情形，例如掷一枚均匀骰子，或从一张编号清单中随机抽取；在软件中的随机整数生成与蒙特卡洛模拟里，它也是实际承担工作的那个分布。<sup>[2](https://mindspaneducation.com/learn/probability-and-statistics/uniform-distribution/)</sup><sup> • </sup><sup>[3](https://www.sciencedirect.com/topics/mathematics/discrete-uniform-distribution)</sup>

| 关键事实 | 说明 |
|---|---|
| 概率质量函数 | 对 \( n \) 个允许取值 \( x \in S \) 中的每一个，\( f(x) = 1/n \)，其余处为零<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup> |
| 均值 | \( \E(X) = a + \tfrac{1}{2}(n-1)h = \tfrac{1}{2}(a+b) \)，即两端点的中点<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup> |
| 方差 | \( \var(X) = \tfrac{1}{12}(n^2-1)h^2 \)；对 \(\{1,\ldots,m\}\) 上的连续整数，为 \( (m^2-1)/12 \)<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup><sup> • </sup><sup>[4](https://www.math.ucla.edu/~plopez/Winter_26/170E/Lecture_notes.pdf)</sup> |
| 均匀骰子 | \( n = 6 \) 给出 \( \E(X) = 3.5 \) 与 \( \var(X) = 35/12 \approx 2.917 \)<sup>[2](https://mindspaneducation.com/learn/probability-and-statistics/uniform-distribution/)</sup> |
| 形状 | 偏度为 0；峰度为 \( \tfrac{3}{5}\tfrac{3n^2-7}{n^2-1} \)，随 \( n \) 增大趋近 1.8<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup> |
| 极限 | 当步长减小到 0 时，收敛到同一区间上的连续均匀分布<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup> |
| 软件 | MATLAB 的 `unidrnd`、NumPy 的 `Generator.integers` 与 R 的 `sample` 都从中抽样<sup>[5](https://www.mathworks.com/help/stats/uniform-distribution-discrete.html)</sup><sup> • </sup><sup>[6](https://numpy.org/doc/stable/reference/random/generated/numpy.random.Generator.integers.html)</sup> |

## 定义与参数化

若对每个 \( i \) 都有 \( \Pr(X = x_i) = 1/n \)，则随机变量 \( X \) 在有限集 \( S = \{x_1, x_2, \ldots, x_n\} \) 上服从离散均匀分布。\( S \) 中的取值不必是整数，也不必等距；例如，Abaqus 的一份参考文档就用 1、2、4 和 8.5 这几个允许取值来说明该分布，每个取值的概率相同。<sup>[7](https://docs.software.vt.edu/abaqusv2025/English/IhrComponentMap/ihr-c-Reference-DiscreteUniform.htm)</sup> 最常见的情形，也是大多数教科书所处理的情形，是连续整数构成的离散区间。<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup>

**位置-尺度形式。** 标准版本把相等的权重放在 \( \{0, 1, \ldots, n-1\} \) 上。加入位置参数 \( a \) 与尺度参数 \( h > 0 \)，便得到 \( S = \{a, a+h, a+2h, \ldots, a+(n-1)h\} \) 上的分布，于是支撑集有 \( n \) 个点，从 \( a \) 开始，步长为 \( h \)。当 \( a \) 为整数且 \( h = 1 \) 时，支撑集就是普通的整数区间，该分布也可以等价地用其端点 \( a \) 与 \( b = a + (n-1)h \) 来参数化，其中 \( n = 1 + (b-a)/h \)。<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup> 这个分布族在位置-尺度变换下封闭：若 \( Y = c + wX \)，则 \( Y \) 仍是离散均匀的，有 \( n \) 个点，位置为 \( c + wa \)，尺度为 \( wh \)。<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup>

## 矩

对 \(\{1, \ldots, m\}\) 上的分布，均值为 \( (m+1)/2 \)，方差为 \( (m^2-1)/12 \)。<sup>[4](https://www.math.ucla.edu/~plopez/Winter_26/170E/Lecture_notes.pdf)</sup> 在端点形式下，均值是两端点的平均值 \( \tfrac{1}{2}(a+b) \)，而方差 \( \tfrac{1}{12}(n^2-1)h^2 \) 只取决于点的个数与步长，与区间所处的位置无关。<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup> 考试中常见的陷阱，是把离散情形的方差 \( (n^2-1)/12 \) 与连续均匀分布的方差 \( (b-a)^2/12 \) 混为一谈。<sup>[2](https://mindspaneducation.com/learn/probability-and-statistics/uniform-distribution/)</sup>

该分布关于其均值对称，因此对任何 \( n \) 偏度都为 0。其峰度为 \( \tfrac{3}{5}\tfrac{3n^2-7}{n^2-1} \)，随 \( n \) 增大而向 1.8 下降。<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup> \(\{1, \ldots, m\}\) 上的矩母函数为

\[ M_X(t) = \begin{cases} \dfrac{e^t(1 - e^{mt})}{m(1 - e^t)}, & t \neq 0, \\[4pt] 1, & t = 0. \end{cases} \]

<sup>[4](https://www.math.ucla.edu/~plopez/Winter_26/170E/Lecture_notes.pdf)</sup>

## 分布函数与分位数函数

与所有离散分布一样，累积分布函数是阶梯函数：它在每个允许取值处上升 \( 1/n \)。在位置-尺度形式下，\( [a, b] \) 上的累积分布函数为 \( F(x) = \tfrac{1}{n}\left(\lfloor (x-a)/h \rfloor + 1\right) \)，分位数函数为 \( F^{-1}(p) = a + h(\lceil np \rceil - 1) \)，其中 \( p \in (0, 1] \)。<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup> MATLAB 的文档用其 `unidcdf` 函数展示了 \( N = 10 \) 时的阶梯状累积分布函数。<sup>[5](https://www.mathworks.com/help/stats/uniform-distribution-discrete.html)</sup>

## 例子

**均匀骰子与轮盘。** 一枚均匀的六面骰子是典范例子：每一面的概率为 \( 1/6 \)，均值为 3.5，方差为 \( 35/12 \)。<sup>[2](https://mindspaneducation.com/learn/probability-and-statistics/uniform-distribution/)</sup> 有 37 个格子的欧洲轮盘，或有 38 个格子的拉斯维加斯轮盘（数字 0 到 36，再加一个双零），都把小球最终停下的位置建模为离散均匀分布。<sup>[8](https://www.statistics4u.com/fundstat_eng/cc_distri_uniform_discrete.html)</sup>

**随机选取。** 从一副标准的 52 张牌中随机抽出一张，或从一张编号清单中挑出一项，只要没有任何结果受到偏爱，就服从离散均匀分布。<sup>[9](https://probabilityplayground.com/discreteuniform)</sup> MATLAB 的例子用 `unidrnd(553,1,10)` 从一张含 553 个项目的清单中抽取 10 个位置的随机样本。<sup>[5](https://www.mathworks.com/help/stats/uniform-distribution-discrete.html)</sup>

**模拟。** 该分布常用于模拟研究——由计算机模仿真实过程，以避免代价高昂或无法进行的实验；生成随机数正是这类蒙特卡洛方法的基本原料。<sup>[3](https://www.sciencedirect.com/topics/mathematics/discrete-uniform-distribution)</sup> 某本教科书给出一种做法：先取一个连续均匀的抽样 \( R \sim U(0,1) \)，计算 \( S = (n+1)R \)，再取 \( S \) 的整数部分，便得到离散均匀的抽样。<sup>[3](https://www.sciencedirect.com/topics/mathematics/discrete-uniform-distribution)</sup>

## 生成离散均匀随机数

软件库直接提供该分布。NumPy 的 `Generator.integers(low, high)` 返回在 \( [\text{low}, \text{high}) \) 上、或在 `endpoint=True` 时于 \( [\text{low}, \text{high}] \) 上服从离散均匀分布的随机整数。<sup>[6](https://numpy.org/doc/stable/reference/random/generated/numpy.random.Generator.integers.html)</sup> R 的 `sample` 函数则从给定的取值向量中抽取均匀随机样本。<sup>[10](https://stat4ds.rwth-aachen.de/pdf/DS_R_webAppendix.pdf)</sup>

在底层实现上，如何由定宽的随机字生成区间 \( [0, s) \) 内一个无偏的整数，是一个真正的算法问题，因为 \( 2^{L} \) 种随机比特模式很少能被 \( s \) 整除。OpenBSD 的 `arc4random_uniform` 函数采用拒绝法，丢弃小于 \( 2^{L} \bmod s \) 的值；它平均消耗不到两个随机字，但总要计算两次求余运算。<sup>[11](https://arxiv.org/abs/1805.10941)</sup> 当时任职于魁北克大学TÉLUQ分校的计算机科学家丹尼尔·勒米尔（Daniel Lemire）在 2018 年发表了另一种方法，以很高的概率避开整数除法；Go 编程语言在其洗牌函数中采用了它，报告的速度比 OpenBSD 的做法约快 30%。<sup>[11](https://arxiv.org/abs/1805.10941)</sup> 一种朴素的浮点做法——把 \( [0,1) \) 上的均匀值乘以 \( s \)——则要慢 10% 到 30%，并且会引入轻微的偏差。<sup>[11](https://arxiv.org/abs/1805.10941)</sup>

## 与其他分布及问题的关系

离散均匀分布是分类分布的特例，后者允许各结果的概率不相等。<sup>[12](https://www.sciencedirect.com/topics/computer-science/bernoulli-distribution)</sup> 当端点固定、步长 \( h \) 向 0 收缩时，该区间上的离散均匀分布收敛到同一区间上的连续均匀分布。<sup>[1](https://www.randomservices.org/random/special/UniformDiscrete.html)</sup>

该分布也是德国坦克问题的基础：二战期间，盟军分析人员依据观察到的序列号来估计敌方坦克的总数 \( N \)。假设坦克从 1 开始连续编号，于是观察到的序列号是 \(\{1, \ldots, N\}\) 上离散均匀分布的一个样本，则由 \( k \) 次观察（最大值为 \( m \)）得到的 \( N \) 的最佳线性无偏估计量为 \( m(1 + 1/k) - 1 \)。<sup>[13](https://arxiv.org/abs/2101.08162)</sup>

## 历史背景

等可能结果的想法来自碰运气的游戏，而概率论正是在这种场景中诞生的。17 世纪中叶，布莱斯·帕斯卡（Blaise Pascal）与皮埃尔·德·费马（Pierre de Fermat）因赌博问题而往来通信，为现代概率论奠定了基础；更早的卢卡·帕乔利（Luca Pacioli）、吉罗拉莫·卡尔达诺（Gerolamo Cardano）与尼科洛·塔尔塔利亚（Nicolò Tartaglia）等人，已经通过清点等可能结果来研究得分问题，即在一场中断的赌局中如何分配赌注。<sup>[14](https://www.aps.org/apsnews/2009/07/pascal-letters-fermat-points)</sup><sup> • </sup><sup>[15](https://library.ethz.ch/en/collections-and-archives/platforms/virtual-exhibitions/Its-all-math-and-games/game-types/from-games-of-chance-to-probability-theory.html)</sup> 离散均匀分布正是那种清点工作的形式化后裔：它是骰子这类实体随机装置的模型，其各结果彼此对称。<sup>[16](https://direct.mit.edu/posc/article/31/6/771/117924/Chance-Combinatorics-The-Theory-that-History)</sup>

## References

1. [Discrete Uniform Distributions, Random Services (Bill Griffiths)](https://www.randomservices.org/random/special/UniformDiscrete.html)
2. [Uniform Distribution PDF, Mean, MindSpan Education](https://mindspaneducation.com/learn/probability-and-statistics/uniform-distribution/)
3. [Discrete Uniform Distribution, ScienceDirect Topics (Statistical Methods, Third Edition, Freund, Rudolf J., William J. Wilson, Donna L. Mohr)](https://www.sciencedirect.com/topics/mathematics/discrete-uniform-distribution)
4. [MATH 170E Lecture Notes, Introduction to Probability and Statistics, UCLA (Pablo López)](https://www.math.ucla.edu/~plopez/Winter_26/170E/Lecture_notes.pdf)
5. [Uniform Distribution (Discrete), MATLAB & Simulink, MathWorks](https://www.mathworks.com/help/stats/uniform-distribution-discrete.html)
6. [numpy.random.Generator.integers, NumPy v2.5 Manual](https://numpy.org/doc/stable/reference/random/generated/numpy.random.Generator.integers.html)
7. [Discrete-Uniform Distribution, Abaqus 2025 Reference Documentation](https://docs.software.vt.edu/abaqusv2025/English/IhrComponentMap/ihr-c-Reference-DiscreteUniform.htm)
8. [Discrete Uniform Distribution, Statistics4u](https://www.statistics4u.com/fundstat_eng/cc_distri_uniform_discrete.html)
9. [Probability Playground: The Discrete Uniform Distribution](https://probabilityplayground.com/discreteuniform)
10. [Data Science Appendix: R for Sampling Distributions, RWTH Aachen](https://stat4ds.rwth-aachen.de/pdf/DS_R_webAppendix.pdf)
11. [Daniel Lemire (2018). Fast Random Integer Generation in an Interval. ACM Transactions on Modeling and Computer Simulation / arXiv.](https://arxiv.org/abs/1805.10941)
12. [Bernoulli Distribution, ScienceDirect Topics](https://www.sciencedirect.com/topics/computer-science/bernoulli-distribution)
13. [Lessons from the German Tank Problem, arXiv](https://arxiv.org/abs/2101.08162)
14. [July 1654: Pascal's Letters to Fermat on the "Problem of Points", APS News](https://www.aps.org/apsnews/2009/07/pascal-letters-fermat-points)
15. [From games of chance to probability theory, ETH Library](https://library.ethz.ch/en/collections-and-archives/platforms/virtual-exhibitions/Its-all-math-and-games/game-types/from-games-of-chance-to-probability-theory.html)
16. [Chance Combinatorics: The Theory that History Forgot, Perspectives on Science, MIT Press](https://direct.mit.edu/posc/article/31/6/771/117924/Chance-Combinatorics-The-Theory-that-History)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 统计学与概率论 › Probability theory › Probability distributions › Distribution families and classification › Discrete distribution families

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/discrete-uniform-distribution

English original: https://www.edgepedia.org/discrete-uniform-distribution
