difference between random module in python 2.6 and 3.2?

Matej Cepl mcepl at redhat.com
Sun Feb 5 20:27:38 EST 2012


I have this working function:

    def as_xml(self):
         out = etree.Element("or")
         for k in sorted(self.keys()):
                 attrib={'op': '=', 'value': random.choice(self[k])}))

	# ... return somehow string representing XML

and this unit test

    def test_XML_print(self):
         expected = ... # expected XML
         observed = self.data.as_xml()
         self.assertEqual(observed, expected,
                          "Verbose print (including PCI IDs)")

Strange thing is that this unit tests correctly with python3, but fails 
with python2. The problem is that apparently python3 random.choice picks 
different element of self[k] than the one python2 (at least, both of 
them are constant in their choice).

Is it known that there is this difference? Is there a way how to make 
both random.choice select the same?



More information about the Python-list mailing list