diff --git a/src/sage/algebras/quatalg/quaternion_algebra.py b/src/sage/algebras/quatalg/quaternion_algebra.py index eb66ce97fce..62847e2ddf2 100644 --- a/src/sage/algebras/quatalg/quaternion_algebra.py +++ b/src/sage/algebras/quatalg/quaternion_algebra.py @@ -2295,6 +2295,20 @@ def __repr__(self): """ return 'Fractional ideal %s' % (self.gens(),) + def random_element(self, *args, **kwds): + """ + Return a random element in the rational fractional ideal ``self``. + + EXAMPLES:: + + sage: B. = QuaternionAlgebra(211) + sage: I = B.ideal([1, 1/4*j, 20*(i+k), 2/3*i]) + sage: x = I.random_element() # random + sage: x in I + True + """ + return sum(ZZ.random_element(*args, **kwds) * g for g in self.gens()) + def quaternion_order(self): """ Return the order for which this ideal is a left or right