python - Using random.choice() with preference and uniqueness -
I have a list:
decisions = ['yes', 'no' , 'Unknown']
I write a file using this list:
X (0, 100) in the range: file.write (Random Options (Decision))
What would be the most effective way to ensure that 70% of values are written as "unknown"?
I want randomness to an extent, but I also want to ensure that the 70 values written in the file are a certain type. I am planning to get this percentage from the user so that he can change every run.
If I had another list which was too large and to ensure uniqueness (no repetitive values, but randomly respectively) is the best way?
If using NumPy is an option for you, then it is quite simple to implement:
np.random.choice (['yes', 'no', 'unknown'], p = [0.15, 0.15, 0.7])
The second array indicates the amount and probability for the P
one that is selected in the first ARA related entry.
The above ensures that 'unknown' is chosen with the possibility of 70% each time.
If you want 100 options with exactly 70 'unknown' entries and 30 'yes' or 'no' option:
< Code> hundred_coreis = ['unknown'] * 70 + [random.choice () ['yes', 'no']) for _ category (30)]
. And then with hundred_coreis
with random.shuffle
.
Comments
Post a Comment