Basically, I know how to get a random number but I'm not sure how to select an item from a list which has a percentage of being randomly selected.
EG. If this is my list
Red - 10%
Blue - 25%
Green - 7%
Yellow - 58%
I then declare a random which selects an item based off their percentage. So yellow is likely to be selected and green the least likely.
How would I go around doing that.
[RESOLVED]
I used some of these posts solutions and wrote the code myself. Its minimal which i like and it works on bigger decimal probabilities.
Code:Dim useRandom As New Random Select Case (Math.Round(useRandom.NextDouble(), 2)) Case 0 To 0.25 MsgBox("Red") Case 0.26 To 0.5 MsgBox("Blue") Case 0.51 To 0.75 MsgBox("Green") Case 0.76 To 1 MsgBox("Yellow") End Select




Reply With Quote