Skip to content

Instantly share code, notes, and snippets.

@dbasilioesp
Last active September 14, 2015 11:41
Show Gist options
  • Save dbasilioesp/7402081f33547396e76a to your computer and use it in GitHub Desktop.
Save dbasilioesp/7402081f33547396e76a to your computer and use it in GitHub Desktop.
#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