ecotyper.rcompat.rng

R’s default random number generator (Mersenne-Twister + Rejection sampling).

This reproduces, draw for draw, set.seed(), unif_rand(), runif() and sample()/sample.int() of R >= 3.6 with the default RNGkind("Mersenne-Twister", "Inversion", "Rejection") (see R’s src/main/RNG.c and src/main/random.c).

Classes

RRandom([seed])

Stateful emulation of R's RNG (.Random.seed).

class ecotyper.rcompat.rng.RRandom(seed=None)[source]

Bases: object

Stateful emulation of R’s RNG (.Random.seed).

Parameters:

seed (int | None)

set_seed(seed)[source]

set.seed(seed) (seed is coerced like as.integer).

Parameters:

seed (int)

Return type:

None

copy()[source]
Return type:

RRandom

property random_seed: ndarray

.Random.seed as R shows it (first element 10403 = kind code).

unif_rand(n=1)[source]
Parameters:

n (int)

Return type:

ndarray

runif(n, min=0.0, max=1.0)[source]
Parameters:
Return type:

ndarray

sample_int(n, size=None, replace=False)[source]

sample.int(n, size, replace); returns 1-based integers like R.

Parameters:
Return type:

ndarray

sample(x, size=None, replace=False)[source]

sample(x, size, replace) for a vector x of length > 1.

Parameters:
permute_rows(data)[source]

t(apply(data, 1, sample)) (R’s bootstrap in calculate_recovery_significance).

Parameters:

data (ndarray)

Return type:

ndarray