std::independent_bits_engine<Engine,W,UIntType>::independent_bits_engine
來自 cppreference.com
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 構造底層引擎。
僅當
Sseq
滿足 SeedSequence 的要求時,此過載才參與過載決議。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; // default-constructed print("e1", e1, 8); std::independent_bits_engine<std::mt19937, /*bits*/ 1, unsigned int> e2(1); // constructed with 1 print("e2", e2, 8); std::random_device rd; std::independent_bits_engine<std::mt19937, /*bits*/ 3, unsigned long> e3(rd()); // seeded with 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); // seeded with seed-sequence 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 呼叫丟擲異常也不會丟擲 |
傳播異常 |