Last active
September 14, 2015 11:41
-
-
Save dbasilioesp/7402081f33547396e76a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cmath> | |
using namespace std; | |
class Random { | |
private: | |
int seed; | |
int lastRandom; | |
int module; | |
int constantMultiple; | |
int constantAditive; | |
public: | |
Random::Random(int _seed){ | |
seed = _seed; | |
lastRandom = seed; | |
module = 64; | |
constantMultiple = 21; | |
constantAditive = 1; | |
} | |
int randomCalc(){ | |
lastRandom = (constantMultiple * lastRandom + constantAditive) % module; | |
return lastRandom; | |
} | |
double randomLCG(){ | |
int calc = randomCalc(); | |
return ((double) calc/(module-1)); | |
} | |
}; | |
int main(){ | |
Random yrandom(3); | |
for (int i = 0; i < 100; i++) | |
{ | |
cout << yrandom.randomCalc() << endl; | |
} | |
system("PAUSE"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment