<random>

公有成員函式
<random>

std::discard_block_engine::operator()

result_type operator()();
生成隨機數
Returns a new random number. (返回一個新的隨機數。)

引擎的轉換演算法內部計數器加一。如果此操作使內部計數器超過了已用塊 (used_block)引數(第三個類模板引數,r),則呼叫其 基類 引擎的discard (丟棄),並將塊大小 (block_size) 與其塊大小 (block_size)和其已用塊 (used_block)作為引數,並重置內部計數器

生成演算法簡單地呼叫其 基類 引擎的operator() (呼叫運算子)並返回其值。

總而言之,此函式產生的效果與在 discard_block_engine 中定義如下的效果相同:
1
2
3
4
5
6
result_type operator() {
  // assuming n is the internal counter, and e the base engine object:
  if (n>=used_block) {e.discard(block_size-used_block); n=0;}
  ++n;
  return e();
}

注意:未完全測試,請報告不準確之處。

引數



返回值

A new random number. (一個新的隨機數。)
result_type (結果型別)是一個成員型別,定義為 基類 引擎生成的數字型別的別名。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// discard_block_engine::operator()
#include <iostream>
#include <chrono>
#include <random>

int main ()
{
  // obtain a seed from the system clock:
  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();

  // ranlux24 is a standard instantitation of discard_block_engine:
  std::ranlux24 generator (seed);
  std::cout << "Random value: " << generator() << std::endl;

  return 0;
}

可能的輸出
Random value: 11370824


複雜度

base 引擎決定。

另見