Ask Your Question

Revision history [back]

The problem with the .random_element() methods in Sage is that the distribution is usually far from being uniform. In some cases, it is very hard to sample according to a particular distribution (even theoretically).

In this case the distribution is indeed concentrated to the integers, as it is specified in the documentation, see:

sage: S.random_element?

Note however that the elements are not integers but belong to S:

sage: S.random_element().parent()
Quotient of Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^256 + 1 by the ideal (xbar^4 - 3)
sage: S.random_element().parent() == S
True

Other distributions are not implemented for such quotient rings, so there is room for interesting development, which is more than welcome !

In the meantime, you can still do something like:

sage: S(ZZ[x].random_element(degree=256))