# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1172858155 28800
# Node ID 6524df91e7a5c301981a72358c532b7b1b60d8c2
# Parent  80001924c68bc224191ac8f3ccd6cd9eac127a70
Fixed some problems with random_element.

diff -r 80001924c68b -r 6524df91e7a5 sage/rings/integer_ring.pyx
--- a/sage/rings/integer_ring.pyx	Fri Mar 02 00:03:59 2007 -0800
+++ b/sage/rings/integer_ring.pyx	Fri Mar 02 09:55:55 2007 -0800
@@ -324,12 +324,14 @@ cdef class IntegerRing_class(PrincipalId
         cdef integer.Integer z, n_max, n_min, n_width
         z = integer.Integer()
         if y is None:
-            if x is None:
+            if x is None or x == 0:
                 mpz_set_si(z.value, random()%5 - 2)
             else:
                 n_max = self(x)
                 mpz_urandomm(z.value, state, n_max.value)
         else:
+            if x >= y:
+                raise ValueError, "upper range must be larger than lower bound."
             n_min = self(x)
             n_width = self(y) - n_min
             mpz_urandomm(z.value, state, n_width.value)
diff -r 80001924c68b -r 6524df91e7a5 sage/rings/polynomial_ring.py
--- a/sage/rings/polynomial_ring.py	Fri Mar 02 00:03:59 2007 -0800
+++ b/sage/rings/polynomial_ring.py	Fri Mar 02 09:55:55 2007 -0800
@@ -466,23 +466,32 @@ class PolynomialRing_general(sage.algebr
         """
         return 1
         
-    def random_element(self, degree, bound=0):
+    def random_element(self, degree, *args, **kwds):
         """
         Return a random polynomial.
         
         INPUT:
             degree -- an integer
-            bound -- an integer (default: 0, which tries to spread choice
-                      across ring, if implemented)
+            *args, **kwds -- passed onto the random_element method for the base ring.
 
         OUTPUT:
             Polynomial -- A polynomial such that the coefficient of x^i,
             for i up to degree, are coercions to the base ring of
             random integers between -bound and bound.
 
+        EXAMPLES:
+            sage: R.<x> = ZZ[]
+            sage: R.random_element(10, 5,10)
+            6*x^10 + 7*x^9 + 8*x^8 + 9*x^7 + 8*x^6 + 9*x^5 + 6*x^4 + 9*x^3 + 5*x^2 + 8*x + 6
+            sage: R.random_element(6)
+            2*x^5 - 2*x^4 - x^3 + 1
+            sage: R.random_element(6)
+            2*x^5 + 2*x^3 + x - 1
+            sage: R.random_element(6)
+            -2*x^6 - x^5 - 2*x^3 - x^2 + 2*x + 1
         """
         R = self.base_ring()
-        return self([R.random_element(bound) for _ in xrange(degree+1)])
+        return self([R.random_element(*args, **kwds) for _ in xrange(degree+1)])
 
     def _monics_degree( self, of_degree ):
         base = self.base_ring()
