Merge pull request #862 from DX-MON/master

common: Improved the random seed initialisation for the context
This commit is contained in:
gatecat 2021-11-19 21:45:07 +00:00 committed by GitHub
commit f5cc959c4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,6 +33,7 @@
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <random>
#include "command.h" #include "command.h"
#include "design_utils.h" #include "design_utils.h"
#include "json_frontend.h" #include "json_frontend.h"
@ -223,12 +224,9 @@ void CommandHandler::setupContext(Context *ctx)
} }
if (vm.count("randomize-seed")) { if (vm.count("randomize-seed")) {
srand(time(NULL)); std::random_device randDev{};
int r; std::uniform_int_distribution<int> distrib{1};
do { ctx->rngseed(distrib(randDev));
r = rand();
} while (r == 0);
ctx->rngseed(r);
} }
if (vm.count("slack_redist_iter")) { if (vm.count("slack_redist_iter")) {