comparison hgext3rd/topic/randomname.py @ 4754:75307f276a79

py3: make random topic name generation consistent across py2/py3 random.choice() (and others based on random.randint()) changed between py2 and py3 without a way to get the py2 behavior. However, random.random() did not change, so we can re-implement random.choice() based on that.
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 17 Jul 2019 11:45:37 -0700
parents 11b12ea01d1e
children 48b30ff742cb dd68ce259708
comparison
equal deleted inserted replaced
4753:87d3955467b4 4754:75307f276a79
1003 'zesty', 1003 'zesty',
1004 'zippy' 1004 'zippy'
1005 ] 1005 ]
1006 1006
1007 def randomtopicname(ui): 1007 def randomtopicname(ui):
1008 # Re-implement random.choice() in the way it was written in Python 2.
1009 def choice(things):
1010 return things[int(len(things) * random.random())]
1008 if ui.configint("devel", "randomseed"): 1011 if ui.configint("devel", "randomseed"):
1009 random.seed(ui.configint("devel", "randomseed")) 1012 random.seed(ui.configint("devel", "randomseed"))
1010 return random.choice(adjectives) + "-" + random.choice(animals) 1013 return choice(adjectives) + "-" + choice(animals)