diff --git a/README.md b/README.md index a86f9c8..08b09f5 100644 --- a/README.md +++ b/README.md @@ -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 ``` diff --git a/prngs/GlibcRand.cpp b/prngs/GlibcRand.cpp index 502565e..e492dea 100644 --- a/prngs/GlibcRand.cpp +++ b/prngs/GlibcRand.cpp @@ -381,7 +381,6 @@ bool GlibcRand::reverseToSeed(uint32_t *outSeed, uint32_t depth) void GlibcRand::tune(std::vector evidenceForward, std::vector evidenceBackward) { tune_chainChecking(); - //tune_fuzzyGuessing(); tune_repeatedIncrements(); } diff --git a/untwister.cpp b/untwister.cpp index ccf3b38..b419011 100644 --- a/untwister.cpp +++ b/untwister.cpp @@ -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 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& pool, bool& isCompleted, uint32_t totalWork, std::vector *status) { double percent = 0; @@ -317,7 +331,7 @@ bool InferState(const std::string& rng) std::vector 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 to provide a file" << std::endl;