# HG changeset patch
# User Frederic Chapoton <chapoton at math.univlyon1.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): 
1592  1592  
1593  1593  
1594  1594  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`. 
1597  1597  
1598  1598  EXAMPLES:: 
1599  1599  
… 
… 
class CombinatorialClass(Parent): 
1601  1601  sage: C.list = lambda: [1,2,3] 
1602  1602  sage: C.random_element() # indirect doctest 
1603  1603  1 
 1604  
 1605  sage: W = Words(5); W 
 1606  Words over {1, 2, 3, 4, 5} 
 1607  sage: W.random_element() 
 1608  word: 151 
1604  1609  """ 
 1610  from sage.rings.infinity import Infinity 
1605  1611  c = self.cardinality() 
 1612  if c is Infinity: 
 1613  c = 100 # a small enough number ? 
1606  1614  r = randint(0, c1) 
1607  1615  return self.unrank(r) 
1608  1616  