MCPcopy Index your code
hub / github.com/python/cpython / choice

Method choice

Lib/random.py:347–354  ·  view source on GitHub ↗

Choose a random element from a non-empty sequence.

(self, seq)

Source from the content-addressed store, hash-verified

345 ## -------------------- sequence methods -------------------
346
347 def choice(self, seq):
348 """Choose a random element from a non-empty sequence."""
349
350 # As an accommodation for NumPy, we don't use "if not seq"
351 # because bool(numpy.array()) raises a ValueError.
352 if not len(seq):
353 raise IndexError('Cannot choose from an empty sequence')
354 return seq[self._randbelow(len(seq))]
355
356 def shuffle(self, x):
357 """Shuffle list x in place, and return None."""

Callers 15

test_choiceMethod · 0.80
test_poll1Method · 0.80
test_parsingMethod · 0.80
setUpClassMethod · 0.80
test_mergeMethod · 0.80
setUpModuleFunction · 0.80
test_devpoll1Method · 0.80
write_test_fileFunction · 0.80
test_randomMethod · 0.80
choose_linesFunction · 0.80
test_selectorMethod · 0.80
test_roundtripMethod · 0.80

Calls

no outgoing calls

Tested by 15

test_choiceMethod · 0.64
test_poll1Method · 0.64
test_parsingMethod · 0.64
setUpClassMethod · 0.64
test_mergeMethod · 0.64
setUpModuleFunction · 0.64
test_devpoll1Method · 0.64
write_test_fileFunction · 0.64
test_randomMethod · 0.64
choose_linesFunction · 0.64
test_selectorMethod · 0.64
test_roundtripMethod · 0.64