16#include "ns3/double.h"
17#include "ns3/random-variable-stream.h"
18#include "ns3/rng-seed-manager.h"
24#include <gsl/gsl_cdf.h>
25#include <gsl/gsl_histogram.h>
52 double increment = (end -
start) / (n - 1.);
88 void DoRun()
override;
92 :
TestCase(
"Uniform Random Number Generator")
103 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
104 gsl_histogram_set_ranges_uniform(h, 0., 1.);
108 gsl_histogram_increment(h, u->
GetValue());
117 tmp[i] = gsl_histogram_get(h, i);
123 gsl_histogram_free(h);
125 double chiSquared = 0;
129 chiSquared += tmp[i];
138 RngSeedManager::SetSeed(
static_cast<uint32_t>(time(
nullptr)));
141 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
181 void DoRun()
override;
185 :
TestCase(
"Normal Random Number Generator")
196 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
203 gsl_histogram_set_ranges(h, range,
N_BINS + 1);
211 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
217 gsl_histogram_increment(h, n->GetValue());
224 tmp[i] = gsl_histogram_get(h, i);
225 tmp[i] -= expected[i];
227 tmp[i] /= expected[i];
230 gsl_histogram_free(h);
232 double chiSquared = 0;
236 chiSquared += tmp[i];
245 RngSeedManager::SetSeed(
static_cast<uint32_t>(time(
nullptr)));
248 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
288 void DoRun()
override;
292 :
TestCase(
"Exponential Random Number Generator")
303 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
309 gsl_histogram_set_ranges(h, range,
N_BINS + 1);
317 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
323 gsl_histogram_increment(h, e->
GetValue());
330 tmp[i] = gsl_histogram_get(h, i);
331 tmp[i] -= expected[i];
333 tmp[i] /= expected[i];
336 gsl_histogram_free(h);
338 double chiSquared = 0;
342 chiSquared += tmp[i];
351 RngSeedManager::SetSeed(
static_cast<uint32_t>(time(
nullptr)));
354 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
394 void DoRun()
override;
398 :
TestCase(
"Pareto Random Number Generator")
409 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
415 gsl_histogram_set_ranges(h, range,
N_BINS + 1);
420 double b = 0.33333333;
426 expected[i] = gsl_cdf_pareto_P(range[i + 1], a, b) - gsl_cdf_pareto_P(range[i], a, b);
432 gsl_histogram_increment(h, p->GetValue());
439 tmp[i] = gsl_histogram_get(h, i);
440 tmp[i] -= expected[i];
442 tmp[i] /= expected[i];
445 gsl_histogram_free(h);
447 double chiSquared = 0;
451 chiSquared += tmp[i];
460 RngSeedManager::SetSeed(
static_cast<uint32_t>(time(
nullptr)));
463 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
491 :
TestSuite(
"random-number-generators", UNIT)
Test case for exponential distribution random number generator.
~RngExponentialTestCase() override
static const uint32_t N_BINS
Number of bins.
void DoRun() override
Implementation to actually run this TestCase.
static const uint32_t N_MEASUREMENTS
Number of measurements.
double ChiSquaredTest(Ptr< ExponentialRandomVariable > n)
Run a chi-squared test on the results of the random number generator.
static const uint32_t N_RUNS
Number of runs.
Test case for normal distribution random number generator.
~RngNormalTestCase() override
double ChiSquaredTest(Ptr< NormalRandomVariable > n)
Run a chi-squared test on the results of the random number generator.
static const uint32_t N_MEASUREMENTS
Number of measurements.
static const uint32_t N_RUNS
Number of runs.
void DoRun() override
Implementation to actually run this TestCase.
static const uint32_t N_BINS
Number of bins.
Test case for pareto distribution random number generator.
static const uint32_t N_RUNS
Number of runs.
~RngParetoTestCase() override
double ChiSquaredTest(Ptr< ParetoRandomVariable > p)
Run a chi-squared test on the results of the random number generator.
void DoRun() override
Implementation to actually run this TestCase.
static const uint32_t N_BINS
Number of bins.
static const uint32_t N_MEASUREMENTS
Number of measurements.
The random number generators Test Suite.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
double GetValue(double mean, double bound)
Get the next random value, as a double from the exponential distribution with the specified mean and ...
void AddTestCase(TestCase *testCase, TestDuration duration=QUICK)
Add an individual child TestCase to this test suite.
void FillHistoRangeUniformly(double *array, uint32_t n, double start, double end)
Fill an array with increasing values, in the [start, end] range.
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static RngTestSuite g_rngTestSuite
Static variable for test initialization.