-Williams [mailto:[EMAIL PROTECTED]]
Sent: Friday, June 29, 2001 3:45 PM
To: [EMAIL PROTECTED]
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
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:
idweight
1 10
25
33
420
52
therefore, since there is a total weight of 40, id 1 should be picked 25%
(10/40) of the time,
How many rows are you likely to have, and how dynamic are the weights?
I think I'd add a cumulative sum column to your table, ie
idweightcum_weight
11010
25 15
3318
42038
52