I need to return different values based on a weighted round-robin such that 1 in 20 gets A, 1 in 20 gets B, and the rest go to C.
So:
A => 5%
B => 5%
C => 90%
Here's a basic version that appears to work:
import random
x = random.randint(1, 100)
if x <= 5:
return 'A'
elif x > 5 and x <= 10:
return 'B'
else:
return 'C'
Is this algorithm correct? If so, can it be improved?
random.randint(1,20)
for your case. – Epidaurus