C# 均衡方式与轮询方式
电脑版发表于:2020/3/2 20:12
均衡方式
private static int iSeed = 0 //调用代码 list.ToArray()[ new Random(iSeed++).Next(0,list.Count()) ]
轮询方式
private static int iSeed = 0 //调用代码 list.ToArray()[ iSeed++ % list.Count()]
权重方式
List<KeyValuePair<string, AgentService>> pairsList = new List<KeyValuePair<string, AgentService>>(); foreach (var item in GetServiceResponse) { int count = int.Parse(item.Value.Tags?[0]); for (int i = 0; i < count; i++) { pairsList.Add(item); } } var keyvaluepair = pairsList.ToArray()[new Random(iSeed++).Next(0, pairsList.Count())];