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++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 2181 | C++11 |
オーバーロード
(
3
)
は、
seq.generate
呼び出しが例外をスローしても例外をスローしない
|
例外を伝播する |