Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit e6a697a

Browse files
author
Jonathan Kliem
committed
truely ignore ignored bounds for ZZ.random_element
1 parent 473cd41 commit e6a697a

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/sage/rings/integer_ring.pyx

+35
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,43 @@ cdef class IntegerRing_class(PrincipalIdealDomain):
709709
sage: ZZ.random_element(11.0, distribution="gaussian")
710710
5
711711
712+
TESTS:
713+
714+
Check that :trac:`32124` is fixed::
715+
716+
sage: ZZ.random_element(5, -5, distribution="1/n").parent() is ZZ
717+
True
718+
sage: ZZ.random_element(5, -5, distribution="gaussian").parent() is ZZ
719+
True
720+
sage: ZZ.random_element(5, -5, distribution="mpz_rrandomb").parent() is ZZ
721+
True
722+
723+
sage: ZZ.random_element(-10, -5, distribution="mpz_rrandomb")
724+
Traceback (most recent call last):
725+
...
726+
TypeError: x must be > 0
727+
sage: ZZ.random_element(-10, -5, distribution="gaussian")
728+
Traceback (most recent call last):
729+
...
730+
TypeError: x must be > 0
731+
732+
Checking error messages::
733+
734+
sage: ZZ.random_element(-3)
735+
Traceback (most recent call last):
736+
...
737+
TypeError: x must be > 0
738+
sage: ZZ.random_element(4, 2)
739+
Traceback (most recent call last):
740+
...
741+
TypeError: x must be < y
712742
"""
713743
cdef Integer z = Integer.__new__(Integer)
744+
if distribution == "1/n":
745+
x = None
746+
y = None
747+
elif distribution == "mpz_rrandomb" or distribution == "gaussian":
748+
y = None
714749
if x is not None and y is None and x <= 0:
715750
raise TypeError("x must be > 0")
716751
if x is not None and y is not None and x >= y:

0 commit comments

Comments
 (0)