UtilityImpl.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Ryujinx.HLE.HOS.Services.Mii.Types;
  2. using Ryujinx.HLE.HOS.Services.Time;
  3. using Ryujinx.HLE.HOS.Services.Time.Clock;
  4. using System;
  5. namespace Ryujinx.HLE.HOS.Services.Mii
  6. {
  7. class UtilityImpl
  8. {
  9. private uint _x;
  10. private uint _y;
  11. private uint _z;
  12. private uint _w;
  13. public UtilityImpl()
  14. {
  15. _x = 123456789;
  16. _y = 362436069;
  17. TimeSpanType time = TimeManager.Instance.TickBasedSteadyClock.GetCurrentRawTimePoint(null);
  18. _w = (uint)(time.NanoSeconds & uint.MaxValue);
  19. _z = (uint)((time.NanoSeconds >> 32) & uint.MaxValue);
  20. }
  21. private uint GetRandom()
  22. {
  23. uint t = (_x ^ (_x << 11));
  24. _x = _y;
  25. _y = _z;
  26. _z = _w;
  27. _w = (_w ^ (_w >> 19)) ^ (t ^ (t >> 8));
  28. return _w;
  29. }
  30. public int GetRandom(int end)
  31. {
  32. return (int)GetRandom((uint)end);
  33. }
  34. public uint GetRandom(uint end)
  35. {
  36. uint random = GetRandom();
  37. return random - random / end * end;
  38. }
  39. public uint GetRandom(uint start, uint end)
  40. {
  41. uint random = GetRandom();
  42. return random - random / (1 - start + end) * (1 - start + end) + start;
  43. }
  44. public int GetRandom(int start, int end)
  45. {
  46. return (int)GetRandom((uint)start, (uint)end);
  47. }
  48. public CreateId MakeCreateId()
  49. {
  50. return new CreateId(Guid.NewGuid().ToByteArray());
  51. }
  52. }
  53. }