Lets say I have an array of numbers like this:
// Create Array Of Numbers
let numbers = ["1","2","3","4","5"]
If I want to print a random number from the array, I can do something like:
pickedNumber = Int.random(in: 0...numbers.count - 1)
The above line will return a random value from my array. What I would like to do is, set a probability for each value in the array. For example:
- Chance of 1 being picked at 10%
- Chance of 2 being picked at 20%
- Chance of 3 being picked at 30%
- Chance of 4 being picked at 35%
- Chance of 5 being picked at 5%
What's the best approach for this? Any guidance or advice would be appreciated. This problem I am facing is in swiftUI.