Added support for generating numbers from an input state file

This commit is contained in:
AltF4 committed 2014-04-25 17:07:41 -07:00
1 parent eb656b8cf8
commit b61797308d
3 files changed
+33 -7

No files matched your search

+3
View File
@@ -43,4 +43,7 @@ Examples:
Generating 70 random numbers from seed 1234, using glibc-rand
./untwister -d 70 -g 1234 -r glibc-rand
Generating 90 random numbers from state file saved in state.txt
./untwister -d 90 -g -i state.txt
```
-1
View File
@@ -381,7 +381,6 @@ bool GlibcRand::reverseToSeed(uint32_t *outSeed, uint32_t depth)
void GlibcRand::tune(std::vector<uint32_t> evidenceForward, std::vector<uint32_t> evidenceBackward)
{
tune_chainChecking();
//tune_fuzzyGuessing();
tune_repeatedIncrements();
}
+30 -6
View File
@@ -131,6 +131,20 @@ void GenerateSample(uint32_t seed, uint32_t depth, std::string rng)
delete generator;
}
/* For easier testing, will generate a series of random numbers at a given seed */
void GenerateSample(std::vector<uint32_t> state, uint32_t depth, std::string rng)
{
PRNGFactory factory;
PRNG *generator = factory.getInstance(rng);
generator->setState(state);
for (unsigned int index = 0; index < depth; ++index)
{
std::cout << generator->random() << std::endl;
}
delete generator;
}
void StatusThread(std::vector<std::thread>& pool, bool& isCompleted, uint32_t totalWork, std::vector<uint32_t> *status)
{
double percent = 0;
@@ -317,7 +331,7 @@ bool InferState(const std::string& rng)
std::vector<uint32_t> state = generator->getState();
for(uint32_t j = 0; j < state.size(); j++)
{
std::cout << SUCCESS << state[j] << std::endl;
std::cout << state[j] << std::endl;
}
}
return true;
@@ -358,6 +372,7 @@ int main(int argc, char *argv[])
uint32_t upperBoundSeed = UINT_MAX;
uint32_t depth = 1000;
uint32_t seed = 0;
bool generateFlag = false;
double minimumConfidence = 100.0;
PRNGFactory factory;
std::string rng = factory.getNames()[0];
@@ -369,6 +384,7 @@ int main(int argc, char *argv[])
case 'g':
{
seed = strtoul(optarg, NULL, 10);
generateFlag = true;
break;
}
case 'u':
@@ -408,7 +424,7 @@ int main(int argc, char *argv[])
std::string line;
while (std::getline(infile, line))
{
observedOutputs.push_back(strtoul(line.c_str(), NULL, 10));
observedOutputs.push_back(strtoul(line.c_str(), NULL, 0));
}
break;
}
@@ -456,13 +472,21 @@ int main(int argc, char *argv[])
}
}
if (seed != 0)
if(generateFlag)
{
GenerateSample(seed, depth, rng);
return EXIT_SUCCESS;
if(observedOutputs.empty())
{
GenerateSample(seed, depth, rng);
return EXIT_SUCCESS;
}
else
{
GenerateSample(observedOutputs, depth, rng);
return EXIT_SUCCESS;
}
}
if (observedOutputs.empty())
if(observedOutputs.empty())
{
Usage(factory, threads);
std::cerr << WARN << "ERROR: No input numbers provided. Use -i <file> to provide a file" << std::endl;