ecpbram: refactor seeding logic.
diff --git a/libtrellis/tools/ecpbram.cpp b/libtrellis/tools/ecpbram.cpp index a1bc205..bffb889 100644 --- a/libtrellis/tools/ecpbram.cpp +++ b/libtrellis/tools/ecpbram.cpp
@@ -124,11 +124,6 @@ int main(int argc, char **argv) { bool verbose = false; -#ifdef _WIN32 - uint32_t seed_nr = GetCurrentProcessId(); -#else - uint32_t seed_nr = getpid(); -#endif namespace po = boost::program_options; std::string database_folder = get_database_path();; @@ -197,14 +192,24 @@ return 1; } + // If -s is provided: seed with the given value. + // If -s is not provided: seed with the PID and current time, which are unlikely + // to repeat simultaneously. + uint32_t seed_nr; if (vm.count("seed")) { seed_nr = vm.at("seed").as<int>(); if (verbose) fprintf(stderr, "Seed: %d\n", seed_nr); + } else { +#ifdef _WIN32 + seed_nr = GetCurrentProcessId(); +#else + seed_nr = getpid(); +#endif } - x = uint64_t(seed_nr) << 32; + x = uint64_t(seed_nr) << 32; x ^= uint64_t(seed_nr) << 20; x ^= uint64_t(seed_nr);