RE: [PHP-DB] most efficient weighting system? URGENT

From: Date: Sun, 01 Jul 2001 23:06:51 +0000
Subject: RE: [PHP-DB] most efficient weighting system? URGENT
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-10004@lists.php.net to get a copy of this message
Well, while this isn't the most efficient way to do it, you could always add the id or link or whatever to the database x times based on the weight you want to give it. Otherwise, you'd have to probably add all weights together, get a total and rand() that total, then count from there using ints... so in the example below, the total value of all weights is 40... rand(40) to get a number... if it was 30, count: +10=10 NO +5=15 NO +3=18 NO +20=38 YES or if the value was 11 +10=10 NO +5=15 YES Think of it like trying to determine random rolls of a x-sided die where x is the value of the total number of sides. This would be the fairest way to ditribute loads, say if you were using this for ad banner linking. Hope this helps! Jesse Williams System Administrator DowNET VoIP Team Electronic Data Systems -----Original Message----- From: Noah Spitzer-Williams [mailto:noahsw@studentcenter.org] Sent: Friday, June 29, 2001 3:45 PM To: php-db@lists.php.net Subject: [PHP-DB] most efficient weighting system? URGENT if i have several rows in a table and i want some to have certain weights what is the best way to pick a random row based on its weight? ex of table: id weight 1 10 2 5 3 3 4 20 5 2 therefore, since there is a total weight of 40, id 1 should be picked 25% (10/40) of the time, id 4 50% (20/40), etc... what is the best way to do this? - Noah -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#10004) next »