Archived
修复了枚举状态扩展中隐藏的缺陷;
添加了在列表中随机获取项目的扩展; 添加了数值转中文格式的繁体字库;
This commit is contained in:
@@ -85,5 +85,23 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 应用算法
|
||||
|
||||
/// <summary>
|
||||
/// 获取列表中随机顺序的对象
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="list"></param>
|
||||
/// <param name="count">需要采样的数量</param>
|
||||
/// <returns></returns>
|
||||
public static IEnumerable<T> GetRandom<T>(this List<T> list, int count = -1)
|
||||
{
|
||||
var index = FisherYatesShuffle(list.Count, count <= 0 ? list.Count : count);
|
||||
for(int i = 0; i < index.Count; i++)
|
||||
yield return list[index[i]];
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user