-
classmethod galois.Poly.Random(degree: int, seed: int | numpy.integer | numpy.random._generator.Generator | None =
None
, field: type[Array] | None =None
) Self Constructs a random polynomial over
with degree .- Parameters:¶
- degree: int¶
The degree of the polynomial.
- seed: int | numpy.integer | numpy.random._generator.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. Anumpy.random.Generator
can also be passed.- field: type[Array] | None =
None
¶ The Galois field
the polynomial is over. The default isNone
which corresponds toGF2
.
- Returns:¶
The polynomial
.
Examples¶
Construct a random degree-5 polynomial over
.In [1]: galois.Poly.Random(5) Out[1]: Poly(x^5 + x^3 + x^2 + 1, GF(2))
Construct a random degree-5 polynomial over
with a given seed. This produces repeatable results.In [2]: GF = galois.GF(3**5) In [3]: galois.Poly.Random(5, seed=123456789, field=GF) Out[3]: Poly(56x^5 + 228x^4 + 157x^3 + 218x^2 + 148x + 43, GF(3^5)) In [4]: galois.Poly.Random(5, seed=123456789, field=GF) Out[4]: Poly(56x^5 + 228x^4 + 157x^3 + 218x^2 + 148x + 43, GF(3^5))
Construct multiple polynomials with one global seed.
In [5]: rng = np.random.default_rng(123456789) In [6]: galois.Poly.Random(5, seed=rng, field=GF) Out[6]: Poly(56x^5 + 228x^4 + 157x^3 + 218x^2 + 148x + 43, GF(3^5)) In [7]: galois.Poly.Random(5, seed=rng, field=GF) Out[7]: Poly(194x^5 + 195x^4 + 200x^3 + 141x^2 + 164x + 119, GF(3^5))