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
  • 184,866
  • 48
  • 414
  • 792
Sarfraz
  • 367,681
  • 72
  • 526
  • 573

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
  • 259,174
  • 73
  • 529
  • 557