UtilityImpl.cs 1.6 KB

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