using System;
using System.Collections.Generic;
///
/// 描述: 根据权重随机抽取指定条数的记录类库
///
public class RandomHelper
{
///
/// 带权重的随机
///
/// 原始列表
/// 随机抽取条数
///
public static List GetRandomList(List list, int count) where T : RandomObject
{
if (list == null || list.Count <= count || count <= 0)
{
return list;
}
//计算权重总和
int totalWeights = 0;
for (int i = 0; i < list.Count; i++)
{
totalWeights += list[i].Weight + 1; //权重+1,防止为0情况。
}
//随机赋值权重
Random ran = new Random(GetRandomSeed()); //GetRandomSeed()随机种子,防止快速频繁调用导致随机一样的问题
List> wlist = new List>(); //第一个int为list下标索引、第一个int为权重排序值
for (in