arkouda.random._generator
¶
Module Contents¶
Classes¶
|
Functions¶
|
Construct a new Generator. |
- class arkouda.random._generator.Generator(name_dict=None, seed=None, state=1)[source]¶
Generator
exposes a number of methods for generating random numbers drawn from a variety of probability distributions. In addition to the distribution-specific arguments, each method takes a keyword argument size that defaults toNone
. If size isNone
, then a single value is generated and returned. If size is an integer, then a 1-D array filled with generated values is returned.- Parameters:
seed (int) – Seed to allow for reproducible random number generation.
name_dict (dict) – Dictionary mapping the server side names associated with the generators for each dtype.
state (int) – The current state we are in the random number generation stream. This information makes it so calls to any dtype generator function affects the stream of random numbers for the other generators. This mimics the behavior we see in numpy
See also
default_rng
Recommended constructor for Generator.
- choice(a, size=None, replace=True, p=None)[source]¶
Generates a randomly sample from a.
- Parameters:
a (int or pdarray) – If a is an integer, randomly sample from ak.arange(a). If a is a pdarray, randomly sample from a.
size (int, optional) – Number of elements to be sampled
replace (bool, optional) – If True, sample with replacement. Otherwise sample without replacement. Defaults to True
p (pdarray, optional) – p is the probabilities or weights associated with each element of a
- Returns:
A pdarray containing the sampled values or a single random value if size not provided.
- Return type:
pdarray, numeric_scalar
- integers(low, high=None, size=None, dtype=akint64, endpoint=False)[source]¶
Return random integers from low (inclusive) to high (exclusive), or if endpoint=True, low (inclusive) to high (inclusive).
Return random integers from the “discrete uniform” distribution of the specified dtype. If high is None (the default), then results are from 0 to low.
- Parameters:
low (numeric_scalars) – Lowest (signed) integers to be drawn from the distribution (unless high=None, in which case this parameter is 0 and this value is used for high).
high (numeric_scalars) – If provided, one above the largest (signed) integer to be drawn from the distribution (see above for behavior if high=None)
size (numeric_scalars) – Output shape. Default is None, in which case a single value is returned.
dtype (dtype, optional) – Desired dtype of the result. The default value is ak.int64.
endpoint (bool, optional) – If true, sample from the interval [low, high] instead of the default [low, high). Defaults to False
- Returns:
Values drawn uniformly from the specified range having the desired dtype, or a single such random int if size not provided.
- Return type:
pdarray, numeric_scalar
Examples
>>> rng = ak.random.default_rng() >>> rng.integers(5, 20, 10) array([15, 13, 10, 8, 5, 18, 16, 14, 7, 13]) # random >>> rng.integers(5, size=10) array([2, 4, 0, 0, 0, 3, 1, 5, 5, 3]) # random
- random(size=None)[source]¶
Return random floats in the half-open interval [0.0, 1.0).
Results are from the uniform distribution over the stated interval.
- Parameters:
size (numeric_scalars, optional) – Output shape. Default is None, in which case a single value is returned.
- Returns:
Pdarray of random floats (unless size=None, in which case a single float is returned).
- Return type:
Notes
To sample over [a,b), use uniform or multiply the output of random by (b - a) and add a:
(b - a) * random() + a
See also
Examples
>>> rng = ak.random.default_rng() >>> rng.random() 0.47108547995356098 # random >>> rng.random(3) array([0.055256829926011691, 0.62511314008006458, 0.16400145561571539]) # random
- shuffle(x)[source]¶
Randomly shuffle a pdarray in place.
- Parameters:
x (pdarray) – shuffle the elements of x randomly in place
- Return type:
None
- standard_normal(size=None)[source]¶
Draw samples from a standard Normal distribution (mean=0, stdev=1).
- Parameters:
size (numeric_scalars, optional) – Output shape. Default is None, in which case a single value is returned.
- Returns:
Pdarray of floats (unless size=None, in which case a single float is returned).
- Return type:
Notes
For random samples from \(N(\mu, \sigma^2)\), use:
(sigma * standard_normal(size)) + mu
Examples
>>> rng = ak.random.default_rng() >>> rng.standard_normal() 2.1923875335537315 # random >>> rng.standard_normal(3) array([0.8797352989638163, -0.7085325853376141, 0.021728052940979934]) # random
- uniform(low=0.0, high=1.0, size=None)[source]¶
Draw samples from a uniform distribution.
Samples are uniformly distributed over the half-open interval [low, high). In other words, any value within the given interval is equally likely to be drawn by uniform.
- Parameters:
low (float, optional) – Lower boundary of the output interval. All values generated will be greater than or equal to low. The default value is 0.
high (float, optional) – Upper boundary of the output interval. All values generated will be less than high. high must be greater than or equal to low. The default value is 1.0.
size (numeric_scalars, optional) – Output shape. Default is None, in which case a single value is returned.
- Returns:
Pdarray of floats (unless size=None, in which case a single float is returned).
- Return type:
Examples
>>> rng = ak.random.default_rng() >>> rng.uniform(-1, 1, 3) array([0.030785499755523249, 0.08505865366367038, -0.38552048588998722]) # random
- arkouda.random._generator.default_rng(seed=None)[source]¶
Construct a new Generator.
Right now we only support PCG64, since this is what is available in chapel.
- Parameters:
seed ({None, int, Generator}, optional) – A seed to initialize the Generator. If None, then the seed will be generated by chapel in an implementation specific manner based on the current time. This behavior is currently unstable and may change in the future. If an int, then the value must be non-negative. If passed a Generator, it will be returned unaltered.
- Returns:
The initialized generator object.
- Return type: