std::uniform_real_distribution
来自cppreference.com
![]() |
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <random> 中定义
|
||
template< class RealType = double > class uniform_real_distribution; |
(C++11 起) | |
产生随机浮点值i,均匀地分布在区间
[a, b)
,即,根据该概率函数分布:原文:
Produces random floating-point values i, uniformly distributed on the interval
[a, b)
, that is, distributed according to the probability function:- P(i|a,b) =
.1 b − a
目录 |
[编辑] 会员类型
会员类型
|
Definition |
result_type
|
RealType |
param_type
|
的类型的参数集,未指定
原文: the type of the parameter set, unspecified |
[编辑] 成员函数
构建新的分配 (公共成员函数) | |
复位内部状态的分布 原文: resets the internal state of the distribution (公共成员函数) | |
| |
生成下一个随机数的分布 原文: generates the next random number in the distribution (公共成员函数) | |
| |
返回“一”分布参数(最小值) 原文: returns the a distribution parameter (minimum value) (公共成员函数) | |
返回“B”分布参数(最大值) 原文: returns the b distribution parameter (maximum value) (公共成员函数) | |
获取或设置的分布参数对象 原文: gets or sets the distribution parameter object (公共成员函数) | |
返回的最低可能产生的价值 原文: returns the minimum potentially generated value (公共成员函数) | |
返回的最大潜在价值 原文: returns the maximum potentially generated value (公共成员函数) |
[编辑] 非成员函数
比较两个分布对象 (函数) | |
执行流输入和输出的伪随机数分布 原文: performs stream input and output on pseudo-random number distribution (函数) |
[编辑] 示例
打印10在1和2之间的随机数
原文:
print 10 random numbers between 1 and 2
#include <random> #include <iostream> int main() { std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> dis(1, 2); for (int n = 0; n < 10; ++n) { std::cout << dis(gen) << ' '; } std::cout << '\n'; }
输出:
1.80829 1.15391 1.18483 1.38969 1.36094 1.0648 1.97798 1.27984 1.68261 1.57326