rrandom

rrandom

Bit-exact reimplementation of R’s default random number generation, so that the Python scripts can reproduce the bootstrap samples and random perturbations of the R scripts.

Reproduces (R >= 3.6 defaults: RNGkind(“Mersenne-Twister”, “Inversion”, “Rejection”)): set.seed(seed) -> RRandom(seed) runif(n) -> rng.runif(n) rnorm(n) -> rng.rnorm(n) sample(x, size, replace = TRUE) -> rng.sample(x, size) (x: array or int n for 1:n)

The draws are consumed from one stream in call order, exactly as in R. So the Python scripts must make the same calls in the same order as the R scripts (including calls for stations that are not computed; use the size of the draw to keep the streams aligned).

Classes

Name Description
RRandom One R random-number stream: RRandom(seed) is equivalent to set.seed(seed).

RRandom

rrandom.RRandom(self, seed)

One R random-number stream: RRandom(seed) is equivalent to set.seed(seed).

Methods

Name Description
rnorm
runif
sample sample(x, size, replace = TRUE); x an array, or an int n meaning 1:n.
set_seed
unif_index R_unif_index(dn) (sample.kind = ‘Rejection’) repeated size times; returns 0-based indices.
unif_rand
rnorm
rrandom.RRandom.rnorm(n, mean=0.0, sd=1.0)
runif
rrandom.RRandom.runif(n, a=0.0, b=1.0)
sample
rrandom.RRandom.sample(x, size)

sample(x, size, replace = TRUE); x an array, or an int n meaning 1:n.

set_seed
rrandom.RRandom.set_seed(seed)
unif_index
rrandom.RRandom.unif_index(dn, size)

R_unif_index(dn) (sample.kind = ‘Rejection’) repeated size times; returns 0-based indices.

unif_rand
rrandom.RRandom.unif_rand(n)

Functions

Name Description
r_qnorm R’s qnorm5(p, 0, 1, lower_tail=TRUE, log_p=FALSE) (Wichura AS241), same operation order.

r_qnorm

rrandom.r_qnorm(p)

R’s qnorm5(p, 0, 1, lower_tail=TRUE, log_p=FALSE) (Wichura AS241), same operation order.