| 100 | |
| 101 | |
| 102 | int cFastRandom::NextInt(int a_Range) |
| 103 | { |
| 104 | ASSERT(a_Range <= 1000000); // The random is not sufficiently linearly distributed with bigger ranges |
| 105 | ASSERT(a_Range > 0); |
| 106 | |
| 107 | // Make the m_Counter operations as minimal as possible, to emulate atomicity |
| 108 | int Counter = m_Counter++; |
| 109 | |
| 110 | // Use a_Range, m_Counter and m_Seed as inputs to the pseudorandom function: |
| 111 | int n = a_Range + Counter * 57 + m_Seed * 57 * 57; |
| 112 | n = (n << 13) ^ n; |
| 113 | n = ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff); |
| 114 | return ((n / 11) % a_Range); |
| 115 | } |
| 116 | |
| 117 | |
| 118 |
no outgoing calls