MCPcopy Create free account
hub / github.com/ActiveState/code / randomPickList

Function randomPickList

recipes/Python/278257_List_Tools/recipe-278257.py:70–75  ·  view source on GitHub ↗

given a list L, with all values are numbers, randomly pick an item and return it's index according to the percentage of all values

(L)

Source from the content-addressed store, hash-verified

68
69#========================================================================
70def randomPickList(L):
71 ''' given a list L, with all values are numbers,
72 randomly pick an item and return it's index according
73 to the percentage of all values'''
74
75 return findIndex(accumList(L,1), random.random())
76
77#========================================================================
78def deepList(LString):

Callers

nothing calls this directly

Calls 3

findIndexFunction · 0.70
accumListFunction · 0.70
randomMethod · 0.45

Tested by

no test coverage detected