Skip to content

Instantly share code, notes, and snippets.

@k5trismegistus
Created August 11, 2014 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k5trismegistus/e3abda6c74e6166ee7df to your computer and use it in GitHub Desktop.
Save k5trismegistus/e3abda6c74e6166ee7df to your computer and use it in GitHub Desktop.
{key, value(数値)}の辞書でルーレット選択
for i in self.pronlist.values():
totalweight += i
r = random.randint(1, totalweight)
for k,v in sorted(self.pronlist.items(), key=lambda x:x[1], reverse=True):
if r <= v:
pron = k
break
else:
r -= v
return pron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment