Skip to content

Commit c8b88af

Browse files
committed
fix the other doctest
1 parent a21e9f4 commit c8b88af

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/sage/categories/rings.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,16 +1647,17 @@ def _random_nonzero_element(self, *args, **kwds):
16471647
if not x.is_zero():
16481648
return x
16491649

1650-
def random_element(self, bound=2):
1650+
def random_element(self, *args):
16511651
"""
16521652
Return a random integer coerced into this ring.
16531653
1654-
The integer is chosen uniformly
1655-
from the interval ``[-bound,bound]``.
1656-
16571654
INPUT:
16581655
1659-
- ``bound`` -- integer (default: 2)
1656+
- either no integer, one integer or two integers
1657+
1658+
The integer is chosen uniformly from the closed interval
1659+
``[-2,2]``, ``[-a,a]`` or ``[a,b]`` according to the
1660+
length of the input.
16601661
16611662
ALGORITHM:
16621663
@@ -1668,8 +1669,17 @@ def random_element(self, bound=2):
16681669
1
16691670
sage: QQ.random_element(8) # random
16701671
2
1672+
sage: ZZ.random_element(4,12) # random
1673+
7
16711674
"""
1672-
return randint(-bound, bound) * self.one()
1675+
if not args:
1676+
a, b = -2, 2
1677+
elif len(args) == 1:
1678+
bound = args[0]
1679+
a, b = -bound, bound
1680+
else:
1681+
a, b = args[0], args[1]
1682+
return randint(a, b) * self.one()
16731683

16741684
class ElementMethods:
16751685
def is_unit(self) -> bool:

0 commit comments

Comments
 (0)