classmethod galois.Poly.Random(degree: int, seed: = None, field: = None) Self

Constructs a random polynomial over $$\mathrm{GF}(p^m)$$ with degree $$d$$.

Parameters:
degree: int

The degree of the polynomial.

seed: = 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.

field: = None

The Galois field $$\mathrm{GF}(p^m)$$ the polynomial is over. The default is None which corresponds to GF2.

Returns:

The polynomial $$f(x)$$.

Examples

Construct a random degree-5 polynomial over $$\mathrm{GF}(2)$$.

In : galois.Poly.Random(5)
Out: Poly(x^5 + x^3 + x^2 + x + 1, GF(2))


Construct a random degree-5 polynomial over $$\mathrm{GF}(3^5)$$ with a given seed. This produces repeatable results.

In : GF = galois.GF(3**5)

In : galois.Poly.Random(5, seed=123456789, field=GF)
Out: Poly(56x^5 + 228x^4 + 157x^3 + 218x^2 + 148x + 43, GF(3^5))

In : galois.Poly.Random(5, seed=123456789, field=GF)
Out: Poly(56x^5 + 228x^4 + 157x^3 + 218x^2 + 148x + 43, GF(3^5))


Construct multiple polynomials with one global seed.

In : rng = np.random.default_rng(123456789)

In : galois.Poly.Random(5, seed=rng, field=GF)
Out: Poly(56x^5 + 228x^4 + 157x^3 + 218x^2 + 148x + 43, GF(3^5))

In : galois.Poly.Random(5, seed=rng, field=GF)
Out: Poly(194x^5 + 195x^4 + 200x^3 + 141x^2 + 164x + 119, GF(3^5))