0

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 banner ad impressions in proportion to the number of impressions remaining for each ad campaign.

hakre
  • 193,403
  • 52
  • 435
  • 836
Sarfraz
  • 377,238
  • 77
  • 533
  • 578

1 Answers1

2

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.

Sampson
  • 265,109
  • 74
  • 539
  • 565