I am trying to write a decorator accepting an argument with the syntax:
@random(0.5)
def func1():
So the probability indicates how likely is the function to be executed.
For example:
@randomly(0.6)
def fa():
return "abc"
@randomly(0.4)
def da():
return "def"
When running:
for i in range(5):
print(da())
it will print the sentences based on probability (3 times 'abc' and twice 'def'):
abc
def
abc
abc
def
Any ideas how it should work? I haven't found anything like that.