We know that if you give weight a probability in the random.choice command, it will be drawn according to that probability. But on the other hand, there's a necessary situation. For example, the lower the probability (number), the higher the probability of being chosen The higher the probability (number), the lower the probability of being picked, or I want to write it either way Is there any way?
python
>>> samples = random.choices([1,2,3,4], weights=[90, 5, 3, 2], k=10000)
>>> counter = collections.Counter(samples)
>>> counter
Counter({1: 9047, 2: 483, 3: 292, 4: 178})
You just have to give weights well. It was roughly 90%, 5%, 3%, and 2%.
You just need to roughly make the weights formula and put it in. You can give me 1/n.
© 2024 OneMinuteCode. All rights reserved.