random_element() improvements

1 view
Skip to first unread message

didier deshommes

unread,
Feb 14, 2007, 2:28:18 AM2/14/07
to sage-devel
Hi,
Here are 2 examples in ZZ that don't work nicely when the range is
invalid in random_element():
{{{
sage: ZZ.random_element(9,-9) # not a valid range
11
sage: ZZ.random_element(9,9) # single element, crashes SAGE
------------------------------------------------------------
Unhandled SIGFPE: An unhandled floating point exception occured in
SAGE.
This probably occured because a *compiled* component
of SAGE has a bug in it (typically accessing invalid memory)
[...]
}}}

I modified ZZ's random_element() method so that it raises a ValueError
when situations like the above occur.

I also gave RR its own random_element() method (it looks like it was
relyin on a generic one). It now that it mimics RDF.random_element():
{{{
sage: RDF.random_element(20)
5.648453007
sage: RR.random_element(20)
15.3961818555746

sage: RDF.random_element(20,30)
24.0967819625
sage: RR.random_element(20,30)
25.3797634155821
}}}

Here is the complete patch:
http://sage.math.washington.edu/home/dfdeshom/custom/patches/random_element-improv.txt

William Stein

unread,
Feb 14, 2007, 10:25:43 AM2/14/07
to sage-...@googlegroups.com
Thanks Didier -- all excellent choices.

 -- William
--
William Stein
Associate Professor of Mathematics
University of Washington
Reply all
Reply to author
Forward
0 new messages