1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-22 21:13:15 +00:00

Avoid the use of rand()

This commit is contained in:
Carles Fernandez 2017-06-07 17:28:11 +02:00
parent 21bf5291f9
commit 8aa7140f19
2 changed files with 14 additions and 7 deletions

View File

@ -37,6 +37,7 @@
#include <ctime>
#include <limits>
#include <numeric>
#include <random>
#include <string>
#include <sys/types.h>
#include <sys/ipc.h>
@ -515,9 +516,10 @@ TEST_F(TTFF_GPS_L1_CA_Test, ColdStart)
std::cout << "Just finished measurement " << num_measurements << ", which took " << ttff << " seconds." << std::endl;
if(n < FLAGS_num_measurements - 1)
{
std::srand(std::time(0)); // use current time as seed for random generator
int random_variable = std::rand();
float random_variable_0_1 = static_cast<float>(random_variable) / static_cast<float>( RAND_MAX );
std::random_device r;
std::default_random_engine e1(r());
std::uniform_real_distribution<float> uniform_dist(0, 1);
float random_variable_0_1 = uniform_dist(e1);
int random_delay_s = static_cast<int>(random_variable_0_1 * 25.0);
std::cout << "Waiting a random amount of time (from 5 to 30 s) to start a new measurement... " << std::endl;
std::cout << "This time will wait " << random_delay_s + 5 << " s." << std::endl << std::endl;
@ -599,9 +601,10 @@ TEST_F(TTFF_GPS_L1_CA_Test, HotStart)
std::cout << "Just finished measurement " << num_measurements << ", which took " << ttff << " seconds." << std::endl;
if(n < FLAGS_num_measurements - 1)
{
std::srand(std::time(0)); // use current time as seed for random generator
int random_variable = std::rand();
float random_variable_0_1 = static_cast<float>(random_variable) / static_cast<float>( RAND_MAX );
std::random_device r;
std::default_random_engine e1(r());
std::uniform_real_distribution<float> uniform_dist(0, 1);
float random_variable_0_1 = uniform_dist(e1);
int random_delay_s = static_cast<int>(random_variable_0_1 * 25.0);
std::cout << "Waiting a random amount of time (from 5 to 30 s) to start new measurement... " << std::endl;
std::cout << "This time will wait " << random_delay_s + 5 << " s." << std::endl << std::endl;

View File

@ -31,6 +31,7 @@
#include <ctime>
#include <complex>
#include <random>
#include <thread>
#include <volk_gnsssdr/volk_gnsssdr.h>
#include "cpu_multicorrelator.h"
@ -100,9 +101,12 @@ TEST(CPU_multicorrelator_test, MeasureExecutionTime)
// generate local reference (1 sample per chip)
gps_l1_ca_code_gen_complex(d_ca_code, 1, 0);
// generate inut signal
std::random_device r;
std::default_random_engine e1(r());
std::uniform_real_distribution<float> uniform_dist(0, 1);
for (int n=0;n<2*d_vector_length;n++)
{
in_cpu[n]=std::complex<float>(static_cast <float> (rand())/static_cast<float>(RAND_MAX),static_cast <float> (rand())/static_cast<float>(RAND_MAX));
in_cpu[n]=std::complex<float>(uniform_dist(e1), uniform_dist(e1));
}
for (int n=0;n<max_threads;n++)