Generates a sequence of pseudo-random numbers using a multiply-with-carry-style recurrence.

cmwc(seed, n, r, bitsize = 32L, a = 7L, c = 4L)

Arguments

seed

Initial seed value for the generator.

n

Number of pseudo-random values to generate.

r

Lag parameter for a complementary multiply-with-carry generator. Currently unused in this implementationde

bitsize

Number of bits used to define the base \(b = 2^{bitsize}\). Defaults to `32`.

a

Multiplier used in the recurrence. Defaults to `7`.

c

Initial carry value. Defaults to `4`.

Value

A numeric vector of length `n` containing the generated pseudo-random values.

Details

The generator updates the state using $$x_i = (a x_{i-1} + c) \bmod b$$ where \(b = 2^{bitsize}\). The carry is updated as $$c = \left\lfloor (a x_{i-1} + c) / b \right\rfloor$$

This implementation uses a multiply-with-carry recurrence. Although the function is named `cmwc`, the current implementation does not use the lag parameter `r` and does not apply the complementary transformation commonly used in full CMWC generators.

Examples

cmwc(seed = 123, n = 10, r = 5)
#>  [1]       865      6055     42385    296695   2076865  14538055 101766385
#>  [8] 712364695 691585569 546131688