Random Number Generators#
Counter-based#
- class heptools.math.random.CBRNG(*seed)[source]#
Counter-based random number generator (CBRNG).
- Parameters:
seed (SeedLike) – The seed used to generate the key.
- normal(counters, loc=0.0, scale=1.0)[source]#
Generates from normal distribution using Box-Muller transform [1].
Warning
In an extremely rare case (\(1/2^{53}\)), it may raise a “divide by zero” warning.
- Parameters:
- Returns:
ndarray – The random sample.
References
- choice(counters, a, p=None)[source]#
Generates a random sample from a given array.
- Parameters:
counters (ArrayLike) – The counter array.
a (ArrayLike or int) – If an array-like object, a random sample is generated by choosing from the first dimension. If an int, the random sample is generated as if it were
np.arange(a)
.p (ArrayLike, optional) – The probabilities associated with each entry in
a
. If not given, the sample assumes a uniform distribution over all entries.
- Returns:
ndarray – The random sample.
Notes
If the
counters
has shape \([x_{1}, x_{2}, ..., x_{n}]\) anda
has shape \([y_{1}, y_{2}, ..., y_{m}]\), the output shape is given as follows:\[\begin{split}&[x_{1}, x_{2}, ..., x_{n-1}, y_{2}, ..., y_{m}] & n > 1 \land m > 1\\ &[x_{1}, x_{2}, ..., x_{n-1}] & n > 1 \land m = 1\\ &[x_{1}, y_{2}, ..., y_{m}] & n = 1 \land m > 1\\ &[x_{1}] & n = 1 \land m = 1\end{split}\]