| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/algorithm.R |
| 3 |
\name{rand_unit} |
| 4 |
\alias{rand_unit} |
| 5 |
\title{Pseudo-random numbers on \verb{[0, 1)} based on a linear congruential generator} |
| 6 |
\usage{ |
| 7 |
rand_unit(n = 1, a = 55797, c = 0, m = 4294967296, seed = NULL) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{n}{The desired length of the sequence.} |
| 11 |
|
| 12 |
\item{a, c, m}{Parameters for the generator (see References for the default |
| 13 |
values).} |
| 14 |
|
| 15 |
\item{seed}{The seed. The default is the system time when this function is |
| 16 |
called for the first time in the current session. For subsequent calls, the |
| 17 |
last \eqn{X_i}{X[i]} of the previous call will be used as the default seed.} |
| 18 |
} |
| 19 |
\value{ |
| 20 |
Random numbers on \verb{[0, 1)} (i.e., \eqn{X/m} instead of \eqn{X}). Note |
| 21 |
the unit interval is open on the right (excluding 1). |
| 22 |
} |
| 23 |
\description{ |
| 24 |
Generate pseudo-random numbers from \eqn{X_{i+1} = (aX_i + c) \bmod{m}}{X\link[=i + |
| 25 |
1]{i + 1} = (a * X\link{i} + c) \%\% m}, where \eqn{X_1}{X[1]} is the initial value (seed). |
| 26 |
} |
| 27 |
\note{ |
| 28 |
All argument values must be smaller than \eqn{2^{64}}{2^64} as they |
| 29 |
will be coerced to 64-bit integers. |
| 30 |
} |
| 31 |
\examples{ |
| 32 |
rand_unit(10) |
| 33 |
rand_unit(10, seed = 0) |
| 34 |
rand_unit(10, seed = 0) # identical results |
| 35 |
rand_unit(10, seed = Sys.getpid()) |
| 36 |
} |
| 37 |
\references{ |
| 38 |
Steele, Guy L. Jr.; Vigna, Sebastiano (2022). "Computationally |
| 39 |
easy, spectrally good multipliers for congruential pseudorandom number |
| 40 |
generators". \emph{Software: Practice and Experience.} 52 (2): 443–458. |
| 41 |
} |