views:

76

answers:

2

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.

+2  A: 

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.

Jonathan Sampson
A: 

A search of php biased random numbers gave this, which almost has the same exactly wording as your question:

http://docstore.mik.ua/orelly/webprog/pcook/ch02%5F07.htm

Oh! Look! StackOverflow is even in those results!

http://stackoverflow.com/questions/445235/generating-random-results-by-weight-in-php

Chacha102