1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-14 09:45:36 +00:00
LatAnalyze/examples/exRand.cpp

43 lines
1.3 KiB
C++
Raw Normal View History

2014-02-10 16:01:39 +00:00
#include <iostream>
2014-03-13 18:51:01 +00:00
#include <LatAnalyze/AsciiFile.hpp>
#include <LatAnalyze/RandGen.hpp>
2014-02-10 16:01:39 +00:00
using namespace std;
using namespace Latan;
const int seqLength = 25;
const int saveStep = 9;
const string stateFileName = "exRand.seed";
int main(void)
{
2014-02-20 23:52:45 +00:00
RandGenState state;
2014-02-10 16:01:39 +00:00
RandGen gen[2];
AsciiFile stateFile(stateFileName, File::Mode::write|File::Mode::read);
cout << "- GENERATOR STATE I/O TESTS" << endl;
cout << "-- generating a " << seqLength << " steps random sequence..."
<< endl;
for (int i = 0; i < seqLength; ++i)
{
if (i == saveStep)
{
state = gen[0].getState();
stateFile.save(state, "exRand");
cout << "generator state after step " << saveStep - 1
<< " saved in '" << stateFileName << "'" << endl;
}
cout << "step " << i << "\t: " << gen[0].uniform() <<endl;
}
cout << "-- setting up another generator from '" << stateFileName << "'..."
<< endl;
2014-02-20 23:52:45 +00:00
gen[1].setState(stateFile.read<RandGenState>("exRand"));
2014-02-10 16:01:39 +00:00
cout << "-- generating a " << seqLength << " steps random sequence..."
<< endl;
for (int i = 0; i < seqLength; ++i)
{
cout << "step " << i << "\t: " << gen[1].uniform() <<endl;
}
return EXIT_SUCCESS;
}