[PHP-DB] Weigting a random selection

2001-12-28 Thread John Hawkins

I have an internal project I'm working on where I
would like to randomly send visitors to different
pages, but, I want to be able to give some pages a
better chance of getting shown. 

So, my thought was that I would have a database table
that had records for each URL and it's weight. Then,
the program could randomly choose a record, but,
taking into account the weighting.

My question is, how in the heck do I make it read the
weighting for each record and then properly figure out
how to make a random selection basted on the weights?

Does that make sense?

Any help is greatly appreciated!

John Hawkins

__
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Weigting a random selection

2001-12-28 Thread Bogdan Stancescu

Yup, that's the roulette selection, as they call it. It's pretty simple,
actually. The idea is that you use a concept similar to a roulette table,
just that the sectors aren't equal -- they're equal to their respective
weights. The procedure is as follows:

1. Assign the weighting to each of the pages;
2. Create an array with the pages' URL's;
3. Create an array with the same size as (2), with the weights of each
respective page to the same index as the URL's;
4. Find out the sum of all values in the array at (3);
5. Generate a random number between 0 and the number found out at (4);
6. Walk (3) while sum of elements in (3) you already walked is smaller than
(5). When the condition is false, remember the index;
7. (6)-1 is the index in (2) you need.

If you need more info, don't hesitate to ask me!

Bogdan

John Hawkins wrote:

 I have an internal project I'm working on where I
 would like to randomly send visitors to different
 pages, but, I want to be able to give some pages a
 better chance of getting shown.


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]