Draw with percentages
Python library for randomizing given elements with the appropriate percentage chance.
Example:
Sample library usage
Code:
from draw_with_percentage import draw_with_percentage
percentages = [
["option1", "10"],
["option2", "20"],
["option3", "30"],
["option4", "40"]
]
res = draw_with_percentage(percentages)
Response:
- Option 1 10% chance will be refunded.
- Option 2 20% chance will be refunded.
- Option 3 30% chance will be refunded.
- Option 4 40% chance will be refunded.
Request:
[
["name", "percent"],
["name", "percent"],
["name", "percent"],
["name", "percent"]
// etc.
]
Remember:
- In the first field we give the name of the element.
- In the second field we give the percentage written as a string.
- We write the percentage down to three places after the decimal point.
- The sum of all percentages must be 100.