From 1b12f2ca2d5bd9cb6f55a10fd41536840cf26e2f Mon Sep 17 00:00:00 2001 From: Andrew Zhen Ning Yong Date: Fri, 13 Nov 2020 07:56:58 +0000 Subject: [PATCH] latan-sample-fake now takes option -r/--seed where seed can be specified if fake bootstrap samples with 100% correlation are needed. --- utils/sample-fake.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/utils/sample-fake.cpp b/utils/sample-fake.cpp index f34921b..5f1816c 100644 --- a/utils/sample-fake.cpp +++ b/utils/sample-fake.cpp @@ -18,30 +18,42 @@ */ #include +#include + using namespace std; using namespace Latan; int main(int argc, char *argv[]) { + OptParser opt; Index nSample; double val, err; string outFileName; - if (argc != 5) + opt.addOption("r", "seed" , OptParser::OptType::value, true, + "random generator seed (default: random)"); + opt.addOption("", "help" , OptParser::OptType::trigger, true, + "show this help message and exit"); + + bool parsed = opt.parse(argc, argv); + if (!parsed or (opt.getArgs().size() != 4) or opt.gotOption("help")) { cerr << "usage: " << argv[0]; cerr << " " << endl; + cerr << endl << "Possible options:" << endl << opt << endl; return EXIT_FAILURE; } + val = strTo(argv[1]); err = strTo(argv[2]); nSample = strTo(argv[3]); outFileName = argv[4]; random_device rd; - mt19937 gen(rd()); + SeedType seed = (opt.gotOption("r")) ? opt.optionValue("r") : rd(); + mt19937 gen(seed); normal_distribution<> dis(val, err); DSample res(nSample); @@ -59,4 +71,4 @@ int main(int argc, char *argv[]) Io::save(res, outFileName); return EXIT_SUCCESS; -} +} \ No newline at end of file