I have an array of elements. each element has a probability value attached to it. Lets say that I have an array of apples, red, yellow, green, blue, etc. like so.

```
- (Apple *)pickRandomApple
{
    Apple *red = [Apple redApple];
    Apple *green = [Apple greenApple];
    Apple *yellow = [Apple yellowApple];
    Apple *blue = [Apple blueApple];

    red.probability = 0.23f;
    green.probability = 0.85f;
    yellow.probability = 0.1f;
    blue.probability = 0.5f;
    NSArray *array = @[red,green,blue,yellow];

    return array[arc4random()%array.count];
}

```

I want to choose a random apple according the to probability property. How can I achieve this?

Thanks!