开发者

PHP: How to generate biased random numbers

I want to generate random numbers, but these numbers should be somewhat biased, so that numbers in certain ranges appear more frequently than others.

For example, to spread out a series of开发者_JS百科 banner ad impressions in proportion to the number of impressions remaining for each ad campaign.


You could generate a random number between 0 and 1, and use it as the percentage of weight for any given banner. If the number is .3 or less, then a less popular (30% of the time) banner will show. If greater, a greater (70% of the time) banner will show.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜