RandomHelper.cs 601 B

12345678910111213141516171819202122232425262728
  1. using System;
  2. namespace Base
  3. {
  4. public static class RandomHelper
  5. {
  6. public static UInt64 RandUInt64()
  7. {
  8. var bytes = new byte[8];
  9. Random random = new Random();
  10. random.NextBytes(bytes);
  11. return BitConverter.ToUInt64(bytes, 0);
  12. }
  13. /// <summary>
  14. /// 获取lower与Upper之间的随机数
  15. /// </summary>
  16. /// <param name="lower"></param>
  17. /// <param name="upper"></param>
  18. /// <returns></returns>
  19. public static int RandomNumber(int lower, int upper)
  20. {
  21. Random ra = new Random(Guid.NewGuid().GetHashCode());
  22. int value = ra.Next(lower, upper);
  23. return value;
  24. }
  25. }
  26. }