Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute a function randomly

Tags:

People also ask

How do I randomly select two variables in Python?

Assuming that L is a list of values you want to choose from, then random. choice(L) will do the job.

How do you randomly add a list in Python?

randint() By using random. randint() we can add random numbers into a list.


Consider the following functions:

def a():
    print "a"
def b():
    print "b"

Is there a way to pick a function to run randomly? I tried using:

random.choice([a(),b()])

but it returns both functions, I just want it to return one function.