修复了枚举状态扩展中隐藏的缺陷;

添加了在列表中随机获取项目的扩展;
添加了数值转中文格式的繁体字库;
This commit is contained in:
2023-10-30 09:40:45 +08:00
parent e293c5592d
commit 42d3fbc69f
3 changed files with 33 additions and 11 deletions
+18
View File
@@ -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
}
}