通过“权重”选择表中的随机条目。
我有一个服务器的MySQL表,我使用RAND()来选择随机服务器每次使用
,但是如何为每个服务器条目添加一个数字
允许它比其他20台服务器更频繁地选择?
例如Server1的重量是80而Server2的重量是40并且
因此Server1比其他人更有可能被选中。
I have a MySQL table of servers, I use RAND() to pick a random server
to use each time, but how can I add a number to each server entry that
allows it be to picked more often than the other 20 servers?
For example Server1''s weight is 80 and Server2''s weight is 40 and
hence Server1 is more likely to be picked than the others.
al ********* @ googlemail.com 写道:
我有一个MySQL服务器表,我用RAND()来选择一个随机服务器
每次使用
,但我怎样才能为每个服务器条目添加一个数字
允许它比其他20台服务器更频繁地选择?
例如Server1的重量是80而Server2的重量是40和
因此Server1比其他人更有可能被选中。
I have a MySQL table of servers, I use RAND() to pick a random server
to use each time, but how can I add a number to each server entry that
allows it be to picked more often than the other 20 servers?
For example Server1''s weight is 80 and Server2''s weight is 40 and
hence Server1 is more likely to be picked than the others.
我不认为myqsl可以做到这一点(如果我错了请核心我)
如果重量不是太大我会解决这样的事情:
如果a = 1,b = 100000000等,这将变得非常无效
link-> weight
a-> 1
b-> 3
c-> 2
- >选择所有链接
- >创建一个新数组
I dont think myqsl can do that (corect me if im wrong please)
If the weights aren''t too large i would solve it something like this:
Offcourse this will get verry ineffective if a=1,b=100000000, etc
link->weight
a->1
b->3
c->2
->select all links
->create a new array
w =(a,b,b,b,c,c)
和voilla
w=(a,b,b,b,c,c)
and voilla
link =