Re: Weigting a random selection

From: Date: Fri, 28 Dec 2001 23:52:54 +0000
Subject: Re: Weigting a random selection
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-15256@lists.php.net to get a copy of this message
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.

« previous php.db (#15256) next »