Original Post
Here's the problem. I have a program involving a lot of pseudo-random numbers. But depending on whether I compile for Release or Debug these numbers are being assigned in a different order, which is making it extremely difficult to debug. I created a simple test case that illustrates the problem: When I cast the value from rand() to a double and compile for Release the rand() calls are reversed. Anyone know how to fix this, so that the rand() calls remain in the same order, independent of Release/Debug mode? Result of running the debug version: Result of running the release version:
#include "conio.h"
#include <stdlib.h>
#include <iostream>
using namespace std;
class MyClass_Double
{
public:
double A, B;
MyClass_Double(double a, double b) {A = a; B = b;}
};
class MyClass_Int
{
public:
int A, B;
MyClass_Int(int a, int b) {A = a; B = b;}
};
int main()
{
//initialize with two random integers
srand(7);
MyClass_Double temp(rand(), rand());
//reset rand(), so that the same numbers are generated
srand(7);
MyClass_Int temp2(rand(), rand());
cout << "MyClass_Double.A = " << temp.A << ", MyClass_Double.B = " << temp.B << endl;
cout << "MyClass_Int.A = " << temp2.A << ", MyClass_Int.B = " << temp2.B << endl;
cout << "Press any key to continue.";
while(!_kbhit());
return 0;
}
MyClass_Double.A = 17422, MyClass_Double.B = 61
MyClass_Int.A = 17422, MyClass_Int.B = 61
Press any key to continue.
MyClass_Double.A = 61, MyClass_Double.B = 17422
MyClass_Int.A = 17422, MyClass_Int.B = 61
Press any key to continue.