<random>

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

std::linear_congruential_engine::max

static constexpr result_type max();
最大值
Returns the maximum value potentially returned by member operator(), which for linear_congruential_engine is (返回成員 operator() 可能返回的最大值,對於 linear_congruential_engine 來說,是)modulus (模數)-1 (where (-1 (其中)modulus (模數)is a member constant, alias of the fourth template parameter, (是一個成員常量,是第四個模板引數的別名,)m).

引數



返回值

modulus-1 (模數-1)
result_type (結果型別)是一個成員型別,定義為第一個類模板引數的別名 (UIntType).

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// linear_congruential_engine::min and max
#include <iostream>
#include <chrono>
#include <random>

int main ()
{
  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
  std::minstd_rand0 generator (seed); // minstd_rand0 is a standard linear_congruential_engine

  std::cout << generator() << " is a random number between ";
  std::cout << generator.min() << " and " << generator.max();

  return 0;
}

可能的輸出
204181028 is a random number between 1 and 2147483646


複雜度

無 (編譯時常量)。

另見