Opened 8 years ago

Closed 7 years ago

# Finite enumerated sets and random elements

Reported by: Owned by: elixyre major sage-duplicate/invalid/wontfix combinatorics finite enumerated sets, random element Travis Scrimshaw N/A

### Description

There is a problem when we try to produce several random element:

```sage: BinaryTrees(5).random_element()
o
/ \
o   o
/
o
\
o
sage: BinaryTrees(5).random_element()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-e0000e9c90c3> in <module>()
----> 1 BinaryTrees(Integer(5)).random_element()

/Users/Jean-Baptiste/sage/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/categories/finite_enumerated_sets.pyc in _random_element_from_unrank(self)
373             """
374             from sage.misc.prandom import randint
--> 375             c = self.cardinality()
376             r = randint(0, c-1)
377             return self.unrank(r)

/Users/Jean-Baptiste/sage/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/misc/cachefunc.so in sage.misc.cachefunc.CachedMethodCaller.__call__ (sage/misc/cachefunc.c:7512)()

TypeError: Expected dict, got sage.rings.integer.Integer
```

or an other example with same problem:

```sage: SetPartitions(4).random_element()
{{1, 2, 3, 4}}
sage: SetPartitions(4).random_element()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-1bf49c0b2651> in <module>()
----> 1 SetPartitions(Integer(4)).random_element()

/Users/Jean-Baptiste/sage/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/categories/finite_enumerated_sets.pyc in _random_element_from_unrank(self)
373             """
374             from sage.misc.prandom import randint
--> 375             c = self.cardinality()
376             r = randint(0, c-1)
377             return self.unrank(r)

/Users/Jean-Baptiste/sage/sage-5.12.beta5/local/lib/python2.7/site-packages/sage/misc/cachefunc.so in sage.misc.cachefunc.CachedMethodCaller.__call__ (sage/misc/cachefunc.c:7512)()

TypeError: Expected dict, got sage.rings.integer.Integer
```

Thanks,

Jean-Baptiste

### comment:1 Changed 8 years ago by vbraun_spam

• Milestone changed from sage-6.1 to sage-6.2

### comment:2 Changed 7 years ago by vbraun_spam

• Milestone changed from sage-6.2 to sage-6.3

### comment:3 Changed 7 years ago by mantepse

I cannot reproduce this on 6.3.beta1.

Neither do I

### comment:5 Changed 7 years ago by tscrim

• Milestone changed from sage-6.3 to sage-duplicate/invalid/wontfix
• Status changed from new to needs_review

Same.

### comment:6 Changed 7 years ago by tscrim

• Reviewers set to Travis Scrimshaw
• Status changed from needs_review to positive_review

### comment:7 Changed 7 years ago by vbraun

• Resolution set to worksforme
• Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.