summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gnuradio-runtime/include/gnuradio/random.h3
-rw-r--r--gnuradio-runtime/lib/math/random.cc5
-rw-r--r--gr-analog/lib/fastnoise_source_impl.cc6
3 files changed, 9 insertions, 5 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);
}
diff --git a/gr-analog/lib/fastnoise_source_impl.cc b/gr-analog/lib/fastnoise_source_impl.cc
index b0ad85d769..a8d6d91650 100644
--- a/gr-analog/lib/fastnoise_source_impl.cc
+++ b/gr-analog/lib/fastnoise_source_impl.cc
@@ -59,7 +59,8 @@ fastnoise_source_impl<T>::fastnoise_source_impl(noise_type_t type,
io_signature::make(0, 0, 0),
io_signature::make(1, 1, sizeof(T))),
d_type(type),
- d_ampl(ampl)
+ d_ampl(ampl),
+ d_rng(seed)
{
d_samples.resize(samples);
xoroshiro128p_seed(d_state, (uint64_t)seed);
@@ -76,7 +77,8 @@ fastnoise_source_impl<gr_complex>::fastnoise_source_impl(noise_type_t type,
io_signature::make(0, 0, 0),
io_signature::make(1, 1, sizeof(gr_complex))),
d_type(type),
- d_ampl(ampl / sqrtf(2.0f))
+ d_ampl(ampl / sqrtf(2.0f)),
+ d_rng(seed)
{
d_samples.resize(samples);
xoroshiro128p_seed(d_state, (uint64_t)seed);