diff options
author | Thomas Habets <thomas@habets.se> | 2020-04-10 11:40:13 +0100 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2020-04-10 16:27:57 +0200 |
commit | 78955a24c6c24f92f7b22ab9223e8e0b60b1dc4b (patch) | |
tree | 09984db7dd2309ebfdb567f3fc3d8c72f42936a0 /gnuradio-runtime | |
parent | 55b6b2724ae872b36dd93c1479a829bb4054bdda (diff) |
runtime: Use nanosecond resolution for default random seed
This exposed some missing forwarding of RNG seed from one object to
another, also fixed in this commit.
Diffstat (limited to 'gnuradio-runtime')
-rw-r--r-- | gnuradio-runtime/include/gnuradio/random.h | 3 | ||||
-rw-r--r-- | gnuradio-runtime/lib/math/random.cc | 5 |
2 files changed, 5 insertions, 3 deletions
diff --git a/gnuradio-runtime/include/gnuradio/random.h b/gnuradio-runtime/include/gnuradio/random.h index 70156f5e3d..30849b0032 100644 --- a/gnuradio-runtime/include/gnuradio/random.h +++ b/gnuradio-runtime/include/gnuradio/random.h @@ -42,8 +42,7 @@ public: /*! * \brief Change the seed for the initialized number generator. seed = 0 initializes - * the random number generator with the system time. Note that a fast initialization - * of various instances can result in the same seed. + * the random number generator with the system time. */ void reseed(unsigned int seed); diff --git a/gnuradio-runtime/lib/math/random.cc b/gnuradio-runtime/lib/math/random.cc index a25cc1c72e..8b67532207 100644 --- a/gnuradio-runtime/lib/math/random.cc +++ b/gnuradio-runtime/lib/math/random.cc @@ -30,6 +30,7 @@ #include <gnuradio/math.h> #include <gnuradio/random.h> +#include <chrono> #include <cmath> namespace gr { @@ -54,7 +55,9 @@ void random::reseed(unsigned int seed) { d_seed = seed; if (d_seed == 0) { - d_rng.seed(time(nullptr)); + auto now = std::chrono::system_clock::now().time_since_epoch(); + auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(now).count(); + d_rng.seed(ns); } else { d_rng.seed(d_seed); } |