linear_congruential_engine 类

通过线性同余算法生成随机序列。

template<class UIntType, UIntType A, UIntType C, UIntType M> class linear_congruential_engine;

参数

  • UIntType
    无符号的整数结果类型。 有关可能的类型,请参阅 <random>

  • A
    乘法器。 前置条件:请参阅“备注”部分。

  • C
    递增。 前置条件:请参阅“备注”部分。

  • M
    取模。 前置条件:请参阅“备注”。

Members

linear_congruential_engine::linear_congruential_engine

linear_congruential_engine::min

linear_congruential_engine::discard

linear_congruential_engine::operator()

linear_congruential_engine::max

linear_congruential_engine::seed

default_seed 是定义为 1u 且用作 linear_congruential_engine::seed 和单个值的构造函数的默认参数值的成员常量。

有关引擎成员的详细信息,请参阅 <random>

备注

linear_congruential_engine 模板类是最简单的生成器引擎,但不是最快速或质量最好的生成器引擎。 substract_with_carry_engine 是对此引擎的改进。 这两个引擎的速度和结果的质量都不如 mersenne_twister_engine

此引擎使用重复关系(周期)x(i) = (A * x(i-1) + C) mod M 产生用户指定的无符号整型值。

如果 M 为零,则用于此取模运算的值是 numeric_limits<result_type>::max() + 1。 引擎的状态是返回的最后一个值,或是种子值(如果尚未对 operator() 进行调用)。

如果 M 不为零,则模板参数 A 和 C 的值必须小于 M。

虽然你可以从此引擎直接构造生成器,但你也可以使用下表中预定义的 typedef 之一。

名称

描述

minstd_rand0

1988 最小标准引擎(Lewis、Goodman 和 Miller,1969)。

typedef linear_congruential_engine<unsigned int, 16807, 0, 2147483647> minstd_rand0;

minstd_rand

更新的最小标准引擎 minstd_rand0(Park、Miller 和 Stockmeyer,1993)。

typedef linear_congruential_engine<unsigned int, 48271, 0, 2147483647> minstd_rand;

有关线性同余引擎算法的详细信息,请参阅 Wikipedia 文章线性同余生成器

要求

标头:<random>

命名空间: std

请参见

参考

<random>