irnorm {iterors} | R Documentation |
Random Number Iterators
Description
These functions each construct an iterator that produces random numbers of various distributions. Each one is a wrapper around a base R function.
Usage
irnorm(
n,
mean = 0,
sd = 1,
count = Inf,
independent = !missing(seed) || !missing(kind),
seed = NULL,
kind = NULL,
normal.kind = NULL,
sample.kind = NULL
)
irbinom(
n,
size,
prob,
count = Inf,
independent = !missing(seed) || !missing(kind),
seed = NULL,
kind = NULL,
normal.kind = NULL,
sample.kind = NULL
)
irnbinom(
n,
size,
prob,
mu,
count = Inf,
independent = !missing(seed) || !missing(kind),
seed = NULL,
kind = NULL,
normal.kind = NULL,
sample.kind = NULL
)
irpois(
n,
lambda,
count = Inf,
independent = !missing(seed) || !missing(kind),
seed = NULL,
kind = NULL,
normal.kind = NULL,
sample.kind = NULL
)
isample(
x,
size,
replace = FALSE,
prob = NULL,
count = Inf,
independent = !missing(seed) || !missing(kind),
seed = NULL,
kind = NULL,
normal.kind = NULL,
sample.kind = NULL
)
irunif(
n,
min = 0,
max = 1,
count = Inf,
independent = !missing(seed) || !missing(kind),
seed = NULL,
kind = NULL,
normal.kind = NULL,
sample.kind = NULL
)
Arguments
n |
How many samples to compute per call; see e.g. rnorm. |
mean |
see rnorm. |
sd |
see rnorm. |
count |
number of times that the iterator will fire. If not specified, it will fire values forever. |
independent |
If TRUE, this iterator will keep its own private
random state, so that its output is reproducible and independent
of anything else in the program; this comes at some performance
cost. Default is FALSE unless |
seed |
A specific seed value for reproducibility. If given,
|
kind |
Which random number algorithm to use; passed along to
set.seed, If given, |
normal.kind |
Passed along to set.seed. |
sample.kind |
Passed along to set.seed. |
size |
see e.g. rbinom. |
prob |
see e.g. rbinom. |
mu |
see rnbinom. |
lambda |
see rpois. |
x |
see isample. |
replace |
see isample. |
min |
see runif. |
max |
see runif. |
Details
Originally from the iterators
package.
Value
An iterator that is a wrapper around the corresponding random number generator function.
See Also
If you are creating multiple independent iterators, iRNGStream will create well-separated seed values, which may help avoid spurious correlations between iterators.
Examples
# create an iterator that returns three random numbers
it <- irnorm(1, count = 3)
nextOr(it)
nextOr(it)
nextOr(it)
nextOr(it, NULL)
# iterators created with a specific seed will make reproducible values
it <- irunif(n=1, seed=314, kind="L'Ecuyer-CMRG")
nextOr(it) # 0.4936700
nextOr(it) # 0.5103891
nextOr(it) # 0.2338745
# the iRNGStream produces a sequence of well separated seed values,
rng.seeds <- iRNGStream(313)
it1 <- isample(c(0, 1), 1, seed=nextOr(rng.seeds))
it2 <- isample(c(0, 1), 1, seed=nextOr(rng.seeds))
it3 <- isample(c(0, 1), 1, seed=nextOr(rng.seeds))
take(it1, 5, "numeric") # 0 1 0 0 1
take(it2, 5, "numeric") # 0 1 0 0 0
take(it3, 5, "numeric") # 0 0 0 1 1