[0, 1) based on a linear congruential generatorR/algorithm.R
rand_unit.RdGenerate pseudo-random numbers from \(X_{i+1} = (aX_i + c) \bmod{m}\), where \(X_1\) is the initial value (seed).
rand_unit(n = 1, a = 55797, c = 0, m = 4294967296, seed = NULL)The desired length of the sequence.
Parameters for the generator (see References for the default values).
The seed. The default is the system time when this function is called for the first time in the current session. For subsequent calls, the last \(X_i\) of the previous call will be used as the default seed.
Random numbers on [0, 1) (i.e., \(X/m\) instead of \(X\)). Note
the unit interval is open on the right (excluding 1).
All argument values must be smaller than \(2^{64}\) as they will be coerced to 64-bit integers.
Steele, Guy L. Jr.; Vigna, Sebastiano (2022). "Computationally easy, spectrally good multipliers for congruential pseudorandom number generators". Software: Practice and Experience. 52 (2): 443–458.
rand_unit(10)
#> [1] 0.9439483 0.4833261 0.1456638 0.6005385 0.2492634 0.1503573 0.4887856
#> [8] 0.7707629 0.2600195 0.3087583
rand_unit(10, seed = 0)
#> [1] 0 0 0 0 0 0 0 0 0 0
rand_unit(10, seed = 0) # identical results
#> [1] 0 0 0 0 0 0 0 0 0 0
rand_unit(10, seed = Sys.getpid())
#> [1] 0.04856761 0.92700539 0.11970340 0.09084078 0.64324534 0.15996830
#> [7] 0.75140533 0.16308901 0.87761715 0.40433084