mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-10-01 08:20:51 +00:00
Avoid the use of rand()
This commit is contained in:
parent
21bf5291f9
commit
8aa7140f19
@ -37,6 +37,7 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <random>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/ipc.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;
|
std::cout << "Just finished measurement " << num_measurements << ", which took " << ttff << " seconds." << std::endl;
|
||||||
if(n < FLAGS_num_measurements - 1)
|
if(n < FLAGS_num_measurements - 1)
|
||||||
{
|
{
|
||||||
std::srand(std::time(0)); // use current time as seed for random generator
|
std::random_device r;
|
||||||
int random_variable = std::rand();
|
std::default_random_engine e1(r());
|
||||||
float random_variable_0_1 = static_cast<float>(random_variable) / static_cast<float>( RAND_MAX );
|
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);
|
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 << "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;
|
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;
|
std::cout << "Just finished measurement " << num_measurements << ", which took " << ttff << " seconds." << std::endl;
|
||||||
if(n < FLAGS_num_measurements - 1)
|
if(n < FLAGS_num_measurements - 1)
|
||||||
{
|
{
|
||||||
std::srand(std::time(0)); // use current time as seed for random generator
|
std::random_device r;
|
||||||
int random_variable = std::rand();
|
std::default_random_engine e1(r());
|
||||||
float random_variable_0_1 = static_cast<float>(random_variable) / static_cast<float>( RAND_MAX );
|
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);
|
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 << "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;
|
std::cout << "This time will wait " << random_delay_s + 5 << " s." << std::endl << std::endl;
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <complex>
|
#include <complex>
|
||||||
|
#include <random>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <volk_gnsssdr/volk_gnsssdr.h>
|
#include <volk_gnsssdr/volk_gnsssdr.h>
|
||||||
#include "cpu_multicorrelator.h"
|
#include "cpu_multicorrelator.h"
|
||||||
@ -100,9 +101,12 @@ TEST(CPU_multicorrelator_test, MeasureExecutionTime)
|
|||||||
// generate local reference (1 sample per chip)
|
// generate local reference (1 sample per chip)
|
||||||
gps_l1_ca_code_gen_complex(d_ca_code, 1, 0);
|
gps_l1_ca_code_gen_complex(d_ca_code, 1, 0);
|
||||||
// generate inut signal
|
// 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++)
|
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++)
|
for (int n=0;n<max_threads;n++)
|
||||||
|
Loading…
Reference in New Issue
Block a user