Anyone knows/suggests the logic to get a random number with some specific weights?
A clear example: banner serving, from a banner pool, you get a banner, and that banner has a weight.
One solution I've seen: create an array with the heavier elements have more copies in the array.

So that: a banner with weight 10 and there are 10 other banners with weight 1, the pool banner will have 11 elements, and the banner with weight 10 appears 10 times!

What I want to ask is another solution(or algorithm)? Or is this one the best algorithm?

you could loop on each banner by the number of the weight you want to give it. For example if I want to give:
Banner A = 10
Banner B = 7
Banner C = 1
Loop on banner A 10 times and keep the largest number by comparing the first and second number...keep the largest...compare against the 3rd...keep the largest and so on.