classmethod galois.FieldArray.Random(shape: ShapeLike = (), low: ElementLike = 0, high: ElementLike | None = None, seed: int | Generator | None = None, dtype: DTypeLike | None = None) FieldArray

Creates an array with random elements.

Parameters
shape: ShapeLike = ()

A NumPy-compliant shape tuple. The default is () which represents a scalar.

low: ElementLike = 0

The smallest element (inclusive). The default is 0.

high: ElementLike | None = None

The largest element (exclusive). The default is None which represents order.

seed: int | Generator | None = None

Non-negative integer used to initialize the PRNG. The default is None which means that unpredictable entropy will be pulled from the OS to be used as the seed. A numpy.random.Generator can also be passed.

dtype: DTypeLike | None = None

The numpy.dtype of the array elements. The default is None which represents the smallest unsigned data type for this FieldArray subclass (the first element in dtypes).

Returns

An array of random elements.

Examples

Generate a random matrix with an unpredictable seed.

In [1]: GF = galois.GF(31)

In [2]: GF.Random((2, 5))
Out[2]: 
GF([[ 0,  1,  5, 22,  7],
    [25, 23,  3, 14,  8]], order=31)

Generate a random array with a specified seed. This produces repeatable outputs.

In [3]: GF.Random(10, seed=123456789)
Out[3]: GF([ 7, 29, 20, 27, 18,  5,  2,  0, 24, 24], order=31)

In [4]: GF.Random(10, seed=123456789)
Out[4]: GF([ 7, 29, 20, 27, 18,  5,  2,  0, 24, 24], order=31)

Generate a group of random arrays using a single global seed.

In [5]: rng = np.random.default_rng(123456789)

In [6]: GF.Random(10, seed=rng)
Out[6]: GF([ 7, 29, 20, 27, 18,  5,  2,  0, 24, 24], order=31)

In [7]: GF.Random(10, seed=rng)
Out[7]: GF([20, 15,  3, 28, 22,  0,  5, 10,  1,  0], order=31)

Last update: Jul 28, 2022