## `polylib::randpoly` -- creates a random polynomial

#### Introduction

`polylib::randpoly``()` returns a univariate random polynomial with integer coefficients; the global identifier `x` is used as an unknown.

`polylib::randpoly``(list)` returns a random polynomial in all unknowns given in `list`.

`polylib::randpoly``(list, ring)` returns a random polynomial in the identifiers given in `list` over the coefficient ring `ring`.

#### Call(s)

`polylib::randpoly()`
`polylib::randpoly(list <, Degree= n> <, Terms= k> <,Coeffs= f>)`
`polylib::randpoly(ring <, Degree= n> <, Terms= k> <,Coeffs= f>)`
`polylib::randpoly(list, ring <, Degree= n> <, Terms= k> <,Coeffs= f>)`

#### Parameters

`list` | - | list of unknowns
`ring` | - | coefficient ring

#### Options

`Degree= k` | - | determines the maximum degree the result can have in each variable. `k` must be a non-negative integer. Default is 6.
`Terms= t` | - | makes `polylib::randpoly` generate the sum of `t` random terms. `t` must be a positive integer or `infinity`. If `t` equals `infinity`, `polylib::randpoly` returns a dense polynomial. Default is 5.
`Coeffs= f` | - | Create the coefficients of the result by calling `f()`.

#### Returns

a polynomial in the given unknowns over the given ring. If no list of indeterminates is given, `[x]` is used. If no ring is given, `Expr` is used.

#### Related Functions

`poly`, `random`

#### Details

- See `poly` for a detailed description of possible unknowns and coefficient rings.
- The polynomial is created by adding the given number (or the default number) of terms, unless the option `Terms=infinity` is given. Each term is created by generating its coefficient and its degree vector at random. Since the same degree vector may be generated several times, the actual number of terms in the result can be smaller than the value of the option `Terms` .
- The random coefficients are generated by calling `f()`, if the option `Coeffs=f` is given. If this option is missing and `ring` is `Expr` the coefficients will be random integers in the range -999..999. If `ring` is a user-defined domain, it must have a method `"random"` to create the coefficients if no function is given.

#### Example 1

We generate a univariate random polynomial and use the default values for the options. Six random monomials are generated and added. Since it is unlikely that each of the possible exponents 0 to 5 is generated exactly once, the result is very likely to have less than six terms.

    >> polylib::randpoly([z])

                              5        4        3
                    poly(663 z  - 764 z  - 806 z  + 381 z, [z])

#### Example 2

We create a bivariate random polynomial over the finite field with 7 elements. This works because `Dom::IntegerMod` has a `"random"` slot that generates random elements:

    >> polylib::randpoly([x,y],Dom::IntegerMod(7),Degree=3,Terms=4);

                     3        2  2
             poly(2 x  y + 6 x  y  + 5 x, [x, y], Dom::IntegerMod(7))

#### Changes

- used to be called `randpoly`

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000