user7364359
user7364359

Reputation: 31

How do i call two of three existent functions randomly

I use of 3 functions with arguments in Python: Func1(a,b), Func2(c,d), Func3(e,f) . all i want is how to call two different functions of these three functions randomly. i have the below code for calling a function randomly too. how could i convert this code to that one which call 2 functions (which is not the same) randomly.

Mylist = [functools.partial(Func1, a, b), functools.partial(Func2, c, d), functools.partial(Func3, e, f)]
random.choice(Mylist)()

Upvotes: 1

Views: 151

Answers (1)

Dan D.
Dan D.

Reputation: 74655

Use random.sample:

for func in random.sample(Mylist, 2):
    func()

Upvotes: 5

Related Questions