import rustymath as rmRandom numbers and distributions
A persistent generator
default_rng(seed) creates one generator whose state advances across calls. A size tuple gives the output shape. Reuse the generator for different distributions:
rng = rm.default_rng(42)
draws = rng.normal(size=(3, 2))
draws, draws.mean(axis=0), rng.sample(rm.distribution.beta(2, 3), 5)(Array([[-1.0920367, -0.30040901], [-0.78924237, 0.52985647], [-2.2347094, 1.3224215]], dtype=float64),
Array([-1.3719962, 0.51728964], dtype=float64),
Array([0.16794595, 0.31556707, 0.25183041, 0.32702751, 0.60316242], dtype=float64))
integers draws from a half-open interval. choice and permutation operate on leading-axis cells; an integer argument denotes a range. Here the two selected items are whole rows:
rng.integers(0, 10, size=4), rng.choice(draws, size=2, replace=False)(Array([5, 3, 0, 4], dtype=int64),
Array([[-1.0920367, -0.30040901], [-2.2347094, 1.3224215]], dtype=float64))
The generator uses rustymath’s shared RNG. It does not reproduce NumPy’s random sequences.
multivariate_normal(mean, cov, size) correlates ordinary normal draws through a Cholesky factor and a matrix product. It takes one real mean vector and real positive-definite covariance matrix, both without axis keys or names, returning float64 samples with a final component axis. A covariance that cannot be factored follows cholesky’s NaN-result policy.
rng.multivariate_normal([1., 2.], [[4., 1.], [1., 3.]], size=3)Array([[-0.90930908, 2.008366], [4.0249491, 6.4071364], [-1.7609395, 1.433404]], dtype=float64)
Probability functions
rm.distribution holds sixteen distributions. Each constructor takes the distribution’s parameters, or uses standard ones where the distribution has them. The result has pdf, cdf, quantile and sample. The same seed gives the same draws:
n = rm.distribution.normal()
n.cdf([-1.96, 0, 1.96]), n.quantile(0.975), n.sample(3, seed=0)(Array([0.024997895, 0.5, 0.9750021], dtype=float64),
1.9599639845400538,
Array([0.11623959, -0.78285485, -2.3346353], dtype=float64))