Jul-22-2020, 07:02 AM
Hi,
Suppose a function that runs over and over again.
At a certain point it calls another function with an argument 'A' or '.B'
Randomly 70% of the time with 'A', 30 % of the time with 'B'. (or any other combination)
The way i implemented this is to make a tuple with the distribution and do a random.choice().
The downside: if i need more than one distribution, like 60-40 or... i need to hard code these tuples.
I could write a function, that creates a tuple on the fly, does the .choice() and returns the result.
But that code then needs to run over and over again, the hard coding beingmore efficient, if there are only a few distributions.
Question: there may be a better way of doing this, an exotic function i never heard of ?
Paul
Suppose a function that runs over and over again.
At a certain point it calls another function with an argument 'A' or '.B'
Randomly 70% of the time with 'A', 30 % of the time with 'B'. (or any other combination)
The way i implemented this is to make a tuple with the distribution and do a random.choice().
A70pct = ('A','A','A','A','A','A','A','B';'B','B') c = random.choice(A70pct)The upside : it is very simple and effective. This will also allow for a third argument 'C', with e.g. a 50-30-20 distribution.etc.
The downside: if i need more than one distribution, like 60-40 or... i need to hard code these tuples.
I could write a function, that creates a tuple on the fly, does the .choice() and returns the result.
But that code then needs to run over and over again, the hard coding beingmore efficient, if there are only a few distributions.
Question: there may be a better way of doing this, an exotic function i never heard of ?
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.