random.shuffle
은 적절한 조작입니다. 목록을 따로 보관하고 임의로 정리해야합니다.
functions = [a, b, c]
shuffle(functions)
는 이제 기능을 단행하고, 당신은 그들에게
for func in functions:
func()
당신은 아마 기능이 저장할 수를 실행해야하고이
def run_functions_in_random_order(*funcs):
functions = list(funcs)
shuffle(functions)
for func in functions:
func()
run_functions_in_random_order(a, b, c)
처럼 할
또는 다음 기능을 사용할 수 있습니다. 폐쇄,이
def run_functions_in_random_order(*funcs):
def run():
functions = list(funcs)
shuffle(functions)
for func in functions:
func()
return run
random_exec = run_functions_in_random_order(a, b, c)
random_exec()
random_exec()
random_exec()
'임의 수입 shuffle'에서 ... Run this Code 보인다. –
아직 코드를 작성하지 않으셨습니까? 당신도 게시해야합니다. 나는 정수가되는 키와 함수 참조가되는 값으로 사전을 만든 다음, 임의의 정수를 사용하여 사전에서 함수를 조회한다고 생각합니다. – Brian