RandomHelper.cs 714 B

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