New submission from Iza Romanowska <izaromanow...@gmail.com>:
Hi, When zero weights are given, the last element of a sequence is always chosen. Example: hits= [] for i in range(100): hits.append(random.choices(["A","B","C","D"], [0, 0, 0, 0])[0]) print (set(hits)) >> {'D'} I guess that most users would expect that in case of zero weights it will default into a random.choice behaviour and select one option at random since this is what happens in cases when all weights are equal. Alternatively, it should return an empty array if the assumption was that all choices have a zero probability of being selected. Either way, if it is consistently choosing one option, this may be potentially difficult to spot in situations when a sequence of weights all equal to zero only happen sporadically. ---------- components: Library (Lib) messages: 357185 nosy: IRomanowska priority: normal severity: normal status: open title: unexpected behaviour of random.choices with zero weights type: behavior versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38881> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com