Utils.cs 718 B

1234567891011121314151617181920212223242526272829303132
  1. using System.Collections.Generic;
  2. using System;
  3. namespace YBEE.EQM.Core;
  4. /// <summary>
  5. /// 工具类型
  6. /// </summary>
  7. public static class Utils
  8. {
  9. /// <summary>
  10. /// List随机乱序
  11. /// </summary>
  12. /// <typeparam name="T"></typeparam>
  13. /// <param name="sources"></param>
  14. public static void ListRandom<T>(List<T> sources)
  15. {
  16. Random rd = new();
  17. int index;
  18. T temp;
  19. for (int i = 0; i < sources.Count; i++)
  20. {
  21. index = rd.Next(0, sources.Count - 1);
  22. if (index != i)
  23. {
  24. temp = sources[i];
  25. sources[i] = sources[index];
  26. sources[index] = temp;
  27. }
  28. }
  29. }
  30. }