How to get a random number with 'weight'?

BlitzMax Forums/BlitzMax Programming/How to get a random number with 'weight'?

Ok, the famous balls in the sack example (no pun intented):

I have 20 balls, 15 are red, 3 are black and 2 are blue

I take one in the sack, the odds are i'll get a red one more often that a black or blue one.

Now lets say i have 3 objects in an array

Array[0].Name = RedBall
Array[0].Weight = 15

Array[1].Name = BlackBall
Array[1].Weight = 3

Array[2].Name = BlueBall
Array[2].Weight = 2

OccurenceTotal = 20

how do i randomize a number from 0 to 2 that takes into account the Weight?

The idea being this: imaging a tetris that once in a while has a special piece instead of the normal ones. The 7 basic tetris pieces would have the same weight, and the specials pieces would have a much smaller weight..

Thanks for the help,

Smurftra (not makign a tetris, just thought it was a clear example)