Boost C++ 库

“……世界上最受推崇和设计精良的 C++ 库项目之一。” Herb SutterAndrei Alexandrescu, C++ 编码标准

PrevUpHomeNext

第 31 章。Boost.Random

Jens Maurer

根据 Boost 软件许可,版本 1.0 分发。(请参阅随附文件 LICENSE_1_0.txt 或复制于 https://boost.ac.cn/LICENSE_1_0.txt

目录

介绍
教程
生成范围内的整数
生成具有不同概率的整数
生成随机密码
生成准随机线-球体交点
参考
概念
生成器
分布
实用程序
头文件
性能
历史和致谢

随机数在各种应用中都很有用。Boost 随机数库(简称 Boost.Random)提供各种生成器分布,以生成具有有用属性的随机数,例如均匀分布。

您应该阅读概念文档以了解基本概念的介绍和定义。 为了快速入门,可以查看random_demo.cpp

为了非常快速的入门,这里有一个例子

boost::random::mt19937 rng;         // produces randomness out of thin air
                                    // see pseudo-random number generators
boost::random::uniform_int_distribution<> six(1,6);
                                    // distribution that maps to 1..6
                                    // see random number distributions
int x = six(rng);                   // simulate rolling a die

PrevUpHomeNext