Algorithm for producing array of objects according to the given distribution
Do you need to guarantee that, in every sample, 50% of the objects are red, 30% are green and 20% are blue? If so, just make your array consist of $0.5\,N$ red objects chosen uniformly at random, followed by $0.3\,N$ green and $0.2\,N$ blue. You'll need to deal with the rounding error if $N$ isn't divisible by&nbsp;$10$.  You can always shuffle the array if it's not desirable to have it sorted by colour.

If you only need to guarantee that the proportions of the colours are correct in the long-run, Apass.Jack's solution will do the job.  If $N$&nbsp;is very large, then each array generation is "the long-run" and will be close to the correct proportions (but not guaranteed to be exact).