public member function (公共成員函式)
<random>
(1) | void seed(); |
---|
(2) | void seed (result_type val); |
---|
(3) | template <class Sseq>void seed (Sseq& q); |
---|
Seed base engine (為基礎引擎設定種子)
Re-initializes the state of the base engine, by calling its (透過呼叫 基礎 引擎的)seed (種子)member function with the same argument (if any). (同名引數(如果存在)成員函式,重新初始化其狀態。)
引數
- val (val)
- A seeding value. This value is passed to the base engine's constructor. (一個種子值。此值會被傳遞給 基礎 引擎的建構函式。)
result_type (結果型別)is a member type, defined as an alias of the type of elements produced by base. (是一個成員型別,定義為 基礎 引擎產生的元素型別的別名。)
- q (q)
- 一個種子序列物件,例如seed_seq型別的物件。
Sseq (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
|
// shuffle_order_engine::seed example
#include <iostream>
#include <chrono>
#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();
// knuth_b is a standard shuffle_order_engine type:
std::knuth_b 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: Knuth
Your seed produced: 361757427
A time seed produced: 1437485371
|
複雜度
Determined by the base engine. (由 基礎 引擎決定。)