std::independent_bits_engine<Engine,W,UIntType>:: independent_bits_engine
From cppreference.net
<
cpp
|
numeric
|
random
|
independent bits engine
C++
Numerics library
| Common mathematical functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical special functions (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical constants (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic linear algebra algorithms (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Data-parallel types (SIMD) (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Floating-point environment (C++11) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Complex numbers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric array (
valarray
)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pseudo-random number generation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bit manipulation (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Saturation arithmetic (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Factor operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Interpolations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Generic numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C-style checked integer arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Pseudo-random number generation
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::independent_bits_engine
| Member functions | ||||
|
independent_bits_engine::independent_bits_engine
|
||||
| Generation | ||||
| Characteristics | ||||
| Non-member functions | ||||
|
(C++11)
(C++11)
(until C++20)
|
||||
|
(C++11)
(C++11)
|
|
independent_bits_engine
(
)
;
|
(1) | (C++11 起) |
|
explicit
independent_bits_engine
(
result_type s
)
;
|
(2) | (C++11 起) |
|
template
<
class
SeedSeq
>
explicit independent_bits_engine ( SeedSeq & seq ) ; |
(3) | (C++11 起) |
|
explicit
independent_bits_engine
(
const
Engine
&
e
)
;
|
(4) | (C++11 起) |
|
explicit
independent_bits_engine
(
Engine
&&
e
)
;
|
(5) | (C++11 起) |
构造新的伪随机引擎适配器。
1)
默认构造函数。底层引擎亦采用默认构造。
2)
使用
s
构造底层引擎。
3)
使用种子序列
seq
构造底层引擎。
4)
使用
e
的副本构造底层引擎。
5)
使用
e
移动构造底层引擎。此后
e
保持未指定但有效的状态。
目录 |
参数
| s | - | 用于构造底层引擎的整数值 |
| seq | - | 用于构造底层引擎的种子序列 |
| e | - | 用于初始化的伪随机数引擎 |
异常
示例
运行此代码
#include <iostream> #include <random> int main() { auto print = [](auto rem, auto engine, int count) { std::cout << rem << ": "; for (int i {}; i != count; ++i) std::cout << static_cast<unsigned>(engine()) << ' '; std::cout << '\n'; }; std::independent_bits_engine<std::mt19937, /*bits*/ 1, unsigned short> e1; // 默认构造 print("e1", e1, 8); std::independent_bits_engine<std::mt19937, /*bits*/ 1, unsigned int> e2(1); // 使用1构造 print("e2", e2, 8); std::random_device rd; std::independent_bits_engine<std::mt19937, /*bits*/ 3, unsigned long> e3(rd()); // 使用rd()作为种子 print("e3", e3, 8); std::seed_seq s {3, 1, 4, 1, 5}; std::independent_bits_engine<std::mt19937, /*bits*/ 3, unsigned long long> e4(s); // 使用种子序列s作为种子 print("e4", e4, 8); }
可能的输出:
e1: 0 0 0 1 0 1 1 1 e2: 1 1 0 0 1 1 1 1 e3: 3 1 5 4 3 2 3 4 e4: 0 2 4 4 4 3 3 6
缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的C++标准。
| 缺陷报告 | 应用于 | 发布时行为 | 正确行为 |
|---|---|---|---|
| LWG 2181 | C++11 |
重载
(
3
)
即使
seq.generate
调用抛出异常也不会抛出
|
传播该异常 |