<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


复杂度

无 (编译时常量)。

另见