//根据传入的概率数组中的概率,随机出一个数值,返回相对应数值的索引值 public static int RandomGetIndexInPercent(IList <float> percent) { if (MNullHelper.IsNullOrEmpty(percent)) { return(MCommonHelper.IsFalse); } float totalPercent = 0f; for (int i = 0; i < percent.Count; i++) { totalPercent += percent[i]; } if (totalPercent <= 0f) { return(MCommonHelper.IsFalse); } float random = RandomExclusive(0, totalPercent); float proportion = 0f; for (int i = 0; i < percent.Count; i++) { proportion += percent[i]; if (random <= proportion) { return(i); } } return(MCommonHelper.IsFalse); }
//移除list中与data相同的所有数据 public static void RemoveMany <T>(List <T> list, IList <T> data) { if (MNullHelper.IsNullOrEmpty(list) || MNullHelper.IsNullOrEmpty(data)) { return; } for (int i = 0; i < data.Count; i++) { for (int j = 0; j < list.Count; j++) { if (MNullHelper.IsEqual(list[j], data[i])) { list.RemoveAt(j); break; } } } }