Ticket #12867: trac_12867.patch

File trac_12867.patch, 1.2 KB (added by chapoton, 7 years ago)
  • sage/combinat/combinat.py

    # HG changeset patch
    # User Frederic Chapoton <chapoton at math.univ-lyon1.fr>
    # Date 1380136309 -7200
    # Node ID 3fb5f13a10e143d8c56355c9908b12233bac83e1
    # Parent  4104d4f1ba99b40029bcc091352f9acc132d543e
    trac #12867 random in infinite sets
    
    diff --git a/sage/combinat/combinat.py b/sage/combinat/combinat.py
    a b class CombinatorialClass(Parent): 
    15921592
    15931593
    15941594    def __random_element_from_unrank(self):
    1595         """
    1596         Default implementation of random which uses unrank.
     1595        r"""
     1596        Default implementation of random which uses :meth:`unrank`.
    15971597
    15981598        EXAMPLES::
    15991599
    class CombinatorialClass(Parent): 
    16011601            sage: C.list = lambda: [1,2,3]
    16021602            sage: C.random_element()       # indirect doctest
    16031603            1
     1604
     1605            sage: W = Words(5); W
     1606            Words over {1, 2, 3, 4, 5}
     1607            sage: W.random_element()
     1608            word: 151
    16041609        """
     1610        from sage.rings.infinity import Infinity
    16051611        c = self.cardinality()
     1612        if c is Infinity:
     1613            c = 100  # a small enough number ?
    16061614        r = randint(0, c-1)
    16071615        return self.unrank(r)
    16081616