mcg31m1

Contents

mcg31m1#

The 31-bit multiplicative congruential pseudorandom number generator MCG(\(1132489760, 2^{32}-1\)) [L’Ecuyer99a].

Description

The mcg31m1 engine is a 31-bit multiplicative congruential generator [L’Ecuyer99]. The mcg31m1 generator belongs to linear congruential generators with the period length of approximately \(2^{31}\). Such generators are still used as default random number generators in various software systems, mainly due to the simplicity of the portable versions implementation, speed, and compatibility with the earlier systems versions. However, their period length does not meet the requirements for modern basic generators. Still, the mcg31m1 generator possesses good statistic properties and you may successfully use it to generate random numbers of different distributions for small samplings.

Generation algorithm

\(x_n=ax_{n-1}(mod \ m)\)

\(u_n = x_n / m\)

\(a = 1132489760, m=2^{31} - 1\)

class mcg31m1#

Syntax

namespace oneapi::math::rng::device {
  template<std::int32_t VecSize = 1>
  class mcg31m1 {
  public:
    static constexpr std::uint32_t default_seed = 1;
    static constexpr std::int32_t vec_size = VecSize;

    mcg31m1();
    mcg31m1(std::uint32_t seed, std::uint64_t offset = 0);
  };
}

Class Template Parameters

VecSize

Describes the size of vector which will be produced by generate function by this engine. VecSize values may be 1, 2, 3, 4, 8, 16 as sycl::vec class size. By default VecSize = 1, for this case, a single random number is returned by the generate function.

Class Members

Routine

Description

mcg31m1()

Default constructor

mcg31m1(std::uint32_t seed, std::uint64_t offset = 0)

Constructor for common seed initialization of the engine and common number of skipped elements

Constructors

mcg31m1::mcg31m1()
mcg31m1::mcg31m1(std::uint32_t seed, std::uint64_t offset = 0)

Input Parameters

seed

The initial conditions of the generator state, assume \(x_0 = seed \ mod \ 0x7FFFFFFF\), if \(x_0 = 0\), assume \(x_0 = 1\).

offset

Number of skipped elements.

Parent topic: Device Engines (Basic Random Number Generators)