Wow thanks for the quick answers. I've though of and used in the previous version of my game the method of creating such an array. The problem i wanted to solve was that i have lots of elements (and they are dynamic) and the array becomes really big and i figured some maths could save me some memory/process time.
The other way I could do it would be to have something like
Array[0].Name = RedBall
Array[0].WeightStart = 1
Array[0].WeightEnd = 15
Array[1].Name = BlackBall
Array[1].WeightStart = 16
Array[1].WeightEnd = 18
Array[2].Name = BlueBall
Array[2].WeightStart = 19
Array[2].WeightEnd = 20
OccurenceTotal = 20
randomizing a number between 1 and 20
and then going through the array to find which one's limits englobes my random number. That would save up on memory but not so sure on cpu time.
The other way I could do it would be to have something like
Array[0].Name = RedBall
Array[0].WeightStart = 1
Array[0].WeightEnd = 15
Array[1].Name = BlackBall
Array[1].WeightStart = 16
Array[1].WeightEnd = 18
Array[2].Name = BlueBall
Array[2].WeightStart = 19
Array[2].WeightEnd = 20
OccurenceTotal = 20
randomizing a number between 1 and 20
and then going through the array to find which one's limits englobes my random number. That would save up on memory but not so sure on cpu time.