<random>

public member function (公共成員函式)
<random>

std::subtract_with_carry_engine::operator()

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

The function advances the internal state by calling its transition algorithm which applies a subtract-with-carry operation on the state sequence element. (該函式透過呼叫其 *轉換演算法* 來推進內部狀態,該演算法對狀態序列元素應用減法進位運算。)

Its generation algorithm is a direct copy of the value generated with the transition algorithm. (它的 *生成演算法* 是使用 *轉換演算法* 生成的值的直接副本。)

引數



返回值

A new random number. (一個新的隨機數。)
result_type (結果型別)是一個成員型別,定義為第一個類模板引數的別名 (UIntType).

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// subtract_with_carry::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();

  std::subtract_with_carry_engine<unsigned,24,10,24> generator (seed);
  std::cout << "Random value: " << generator() << std::endl;

  return 0;
}

可能的輸出
Random value: 2780326


複雜度

Amortized constant. (分攤常數。)

另見