公有成员函数
<random>

std::independent_bits_engine::seed

(1)
void seed();
(2)
void seed (result_type val);
(3)
template <class Sseq>void seed (Sseq& q);
Seed base engine (为基础引擎设置种子)
通过调用其 base 引擎的构造函数来重新初始化 base 引擎的状态。seedmember function with the same argument (if any). (同名参数(如果存在)成员函数,重新初始化其状态。)

参数

val
一个种子值。该值将传递给 base 引擎的构造函数。
result_type是成员类型,定义为 base 生成的元素类型的别名。
q
一个种子序列对象,例如seed_seq类型的对象。
Sseq应为具有generate成员函数的种子序列类。

返回值



示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// independent_bits_engine::seed example
#include <iostream>
#include <chrono>
#include <cstdint>
#include <random>

int main ()
{
  typedef std::chrono::high_resolution_clock myclock;
  myclock::time_point beginning = myclock::now();

  // obtain a seed from a user string:
  std::string str;
  std::cout << "Please, enter a seed: ";
  std::getline(std::cin,str);
  std::seed_seq seed1 (str.begin(),str.end());

  // obtain a seed from the timer
  myclock::duration d = myclock::now() - beginning;
  unsigned seed2 = d.count();

  std::independent_bits_engine<std::mt19937,64,std::uint_fast64_t> generator (seed1);
  std::cout << "Your seed produced: " << generator() << std::endl;

  generator.seed (seed2);
  std::cout << "A time seed produced: " << generator() << std::endl;

  return 0;
}

可能的输出
Please, enter a seed: give me numbers
Your seed produced: 8733447681123360525
A time seed produced: 8954499881567149160


复杂度

Determined by the base engine. (由base引擎决定。)

另见