If anyone get's any free time see if you can get the following function ( part of the CRandom class ) to return a negetive number ( specifically -0.5000 it seems ). It seems to do it rather often, maybe 1 out of 10 times. I haven't figured out why and I've set the seed both on my own and through ::Randomize().
Let me know if you find the same result.
// Returns a random float between 0.0f-1.0f
// NEW for Game Code Complete 2nd Edition!
EDIT: After doing some research it seems as though r comes up as -2147483648 for some reason... and it actually seems to do it more then I originally thought. So it seems as though the problem is with the CRandom::Random( unsigned int ) not the above one. ( Both are located in the CMath_Random.cpp )
Below is this function.
Display All
Let me know if you find the same result.
// Returns a random float between 0.0f-1.0f
// NEW for Game Code Complete 2nd Edition!
EDIT: After doing some research it seems as though r comes up as -2147483648 for some reason... and it actually seems to do it more then I originally thought. So it seems as though the problem is with the CRandom::Random( unsigned int ) not the above one. ( Both are located in the CMath_Random.cpp )
Below is this function.
Source Code
- // Returns a number from 0 to n (excluding n)
- unsigned int CRandom::Random( unsigned int n )
- {
- unsigned long y;
- static unsigned long mag01[2]={0x0, CMATH_MATRIX_A};
- if(n==0)
- return(0);
- /* mag01[x] = x * MATRIX_A for x=0,1 */
- if (mti >= CMATH_N) { /* generate N words at one time */
- int kk;
- if (mti == CMATH_N+1) /* if sgenrand() has not been called, */
- SetRandomSeed(4357); /* a default initial seed is used */
- for (kk=0;kk<CMATH_N-CMATH_M;kk++) {
- y = (mt[kk]&CMATH_UPPER_MASK)|(mt[kk+1]&CMATH_LOWER_MASK);
- mt[kk] = mt[kk+CMATH_M] ^ (y >> 1) ^ mag01[y & 0x1];
- }
- for (;kk<CMATH_N-1;kk++) {
- y = (mt[kk]&CMATH_UPPER_MASK)|(mt[kk+1]&CMATH_LOWER_MASK);
- mt[kk] = mt[kk+(CMATH_M-CMATH_N)] ^ (y >> 1) ^ mag01[y & 0x1];
- }
- y = (mt[CMATH_N-1]&CMATH_UPPER_MASK)|(mt[0]&CMATH_LOWER_MASK);
- mt[CMATH_N-1] = mt[CMATH_M-1] ^ (y >> 1) ^ mag01[y & 0x1];
- mti = 0;
- }
- y = mt[mti++];
- y ^= CMATH_TEMPERING_SHIFT_U(y);
- y ^= CMATH_TEMPERING_SHIFT_S(y) & CMATH_TEMPERING_MASK_B;
- y ^= CMATH_TEMPERING_SHIFT_T(y) & CMATH_TEMPERING_MASK_C;
- y ^= CMATH_TEMPERING_SHIFT_L(y);
- // ET - old engine added one to the result.
- // We almost NEVER wanted to use this function
- // like this. So, removed the +1 to return a
- // range from 0 to n (not including n).
- return (y%n);
- }
The post was edited 2 times, last by Alien_Attack ().