RandomHelper.cs 702 B

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