diff --git a/tests/functional/single_cells/vcd_harness.cc b/tests/functional/single_cells/vcd_harness.cc index 18c9ed5df..9b3777c37 100644 --- a/tests/functional/single_cells/vcd_harness.cc +++ b/tests/functional/single_cells/vcd_harness.cc @@ -34,9 +34,7 @@ struct Dump { }; template -Signal random_signal() { - std::random_device rd; // Random device for seeding - std::mt19937 gen(rd()); // Mersenne Twister engine +Signal random_signal(std::mt19937 &gen) { std::uniform_int_distribution dist; std::array words; for(auto &w : words) @@ -52,9 +50,12 @@ struct Reset { }; struct Randomize { + std::mt19937 &gen; + Randomize(std::mt19937 &gen) : gen(gen) {} + template void operator()(const char *, Signal &signal) { - signal = random_signal(); + signal = random_signal(gen); } }; @@ -89,7 +90,7 @@ int main(int argc, char **argv) vcd_file << "#0\n"; // Set all signals to false inputs.visit(Reset()); - + gold::eval(inputs, outputs, state, next_state); { Dump d(vcd_file); @@ -97,11 +98,15 @@ int main(int argc, char **argv) outputs.visit(d); state.visit(d); } - + + // Initialize random number generator once + std::random_device rd; + std::mt19937 gen(rd()); + for (int step = 0; step < steps; ++step) { // Functional backend cxx vcd_file << "#" << (step + 1) << "\n"; - inputs.visit(Randomize()); + inputs.visit(Randomize(gen)); gold::eval(inputs, outputs, state, next_state); { @@ -110,7 +115,7 @@ int main(int argc, char **argv) outputs.visit(d); state.visit(d); } - + state = next_state; }