Hi,
this is because PolynomialRing().random_element() takes an optional
argument degree which should either be an integer greater or equal to
-1, or an ordered pair of such integers which defines an integer range
in which the degree is selected uniformly at random. By convention,
degree -1 yields the 0 polynomial, degree 0 yields a constant non zero
and so on.
By default, this argument is set to (-1, 2), which means that which 25%
probability, degree -1 will be selected, and this is exactly what you
observe with your experiment. But you can set degree to whatever suits
you better, e.g. starting with 0 instead of -1 to avoid the 0 polynomial.
For more information:
https://doc.sagemath.org/html/en/reference/polynomial_rings/sage/rings/polynomial/polynomial_ring.html#sage.rings.polynomial.polynomial_ring.PolynomialRing_general.random_element
Best,
--
Maxime