From AriDEV, 11 Months ago, written in Diff-output.
Embed
  1. diff --git a/src/server/shared/Utilities/Util.cpp b/src/server/shared/Utilities/Util.cpp
  2. index 26640e9..e756681 100644
  3. --- a/src/server/shared/Utilities/Util.cpp
  4. +++ b/src/server/shared/Utilities/Util.cpp
  5. @@ -27,6 +27,76 @@
  6.  typedef ACE_TSS<SFMTRand> SFMTRandTSS;
  7.  static SFMTRandTSS sfmtRand;
  8.  
  9. +int64 sfllrand(uint64 min, uint64 max)
  10. +{
  11. +    ASSERT(max >= min);
  12. +
  13. +    // Output random integer in the interval min <= x <= max
  14. +    // Slightly inaccurate if (max-min+1) is not a power of 2
  15. +    if (max <= min) {
  16. +        if (max == min) return min; else return 0x80000000;
  17. +    }
  18. +    int64 interval;                  // Length of interval
  19. +    int64 longran;                   // Random bits * interval
  20. +
  21. +    interval = (int64)(max - min + 1);
  22. +    longran = (int64)SFRandom() * interval;
  23. +    // Convert back to signed and return result
  24. +    return (int64)longran + min;
  25. +}
  26. +uint64 sfullrand(uint64 min, uint64 max)
  27. +{
  28. +    ASSERT(max >= min);
  29. +
  30. +    // Output random integer in the interval min <= x <= max
  31. +    // Slightly inaccurate if (max-min+1) is not a power of 2
  32. +    if (max <= min) {
  33. +        if (max == min) return min; else return 0x80000000;
  34. +    }
  35. +    uint64 interval;                  // Length of interval
  36. +    uint64 longran;                   // Random bits * interval
  37. +
  38. +    interval = (uint64)(max - min + 1);
  39. +    longran = (uint64)SFRandom() * interval;
  40. +    // Convert back to signed and return result
  41. +    return (uint64)longran + min;
  42. +}
  43. +
  44. +uint64 SFRandom()                            // Output random bits
  45. +{
  46. +    __m128i  mask;                                // AND mask
  47. +    __m128i  state[SFMT_N];                       // State vector for SFMT generator
  48. +    uint64 ix;                                  // Index into state array
  49. +
  50. +    // Output 32 random bits
  51. +    uint64 y;
  52. +
  53. +    if (ix >= SFMT_N * 4)
  54. +    {
  55. +        // Fill state array with new random numbers
  56. +        int i;
  57. +        __m128i r, r1, r2;
  58. +
  59. +        r1 = state[SFMT_N - 2];
  60. +        r2 = state[SFMT_N - 1];
  61. +        for (i = 0; i < SFMT_N - SFMT_M; i++) {
  62. +            r = sfmt_recursion(state[i], state[i + SFMT_M], r1, r2, mask);
  63. +            state[i] = r;
  64. +            r1 = r2;
  65. +            r2 = r;
  66. +        }
  67. +        for (; i < SFMT_N; i++) {
  68. +            r = sfmt_recursion(state[i], state[i + SFMT_M - SFMT_N], r1, r2, mask);
  69. +            state[i] = r;
  70. +            r1 = r2;
  71. +            r2 = r;
  72. +        }
  73. +        ix = 0;
  74. +    }
  75. +    y = ((uint64*)state)[ix++];
  76. +    return y;
  77. +}
  78. +
  79.  int32 irand(int32 min, int32 max)
  80.  {
  81.      ASSERT(max >= min);
  82.