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 Sseq >
explicit independent_bits_engine( Sseq& 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 - 用以初始化的伪随机数引擎

[编辑]异常

3) 如果 SeedSeq 不是 std::seed_seq,那么就会抛出 seq.generate 调用抛出的异常。

[编辑]示例

#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, unsignedshort> e1;// 默认构造 print("e1", e1, 8);   std::independent_bits_engine<std::mt19937, /*bits*/1, unsignedint> e2(1);// 以 l 构造 print("e2", e2, 8);   std::random_device rd;std::independent_bits_engine<std::mt19937, /*bits*/3, unsignedlong> e3(rd());// 以 rd() 播种 print("e3", e3, 8);   std::seed_seq s {3, 1, 4, 1, 5};std::independent_bits_engine<std::mt19937, /*bits*/3, unsignedlonglong> 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 即使 seq.generate 调用抛出了异常,重载 (3) 也不会抛出异常 会传播该异常
close