aboutsummaryrefslogtreecommitdiffstats
path: root/src/test_rtnorm.cpp
diff options
context:
space:
mode:
authorBertrand <bertrand.horel@gmail.com>2016-02-19 15:03:51 +0000
committerBertrand <bertrand.horel@gmail.com>2016-02-19 15:03:51 +0000
commitd2b133901a65244934eb642ec8e20c797efaf650 (patch)
treef8d186f8e8ca0886f8f0a464261ba8747242b4e6 /src/test_rtnorm.cpp
parent355e4567e68a76356714e2e58a42dcd78533cf6c (diff)
downloadprojet_C++-d2b133901a65244934eb642ec8e20c797efaf650.tar.gz
nettoyage du dépôt
Diffstat (limited to 'src/test_rtnorm.cpp')
-rw-r--r--src/test_rtnorm.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/test_rtnorm.cpp b/src/test_rtnorm.cpp
new file mode 100644
index 0000000..48ce933
--- /dev/null
+++ b/src/test_rtnorm.cpp
@@ -0,0 +1,45 @@
+// Example for using rtnorm
+//
+// Copyright (C) 2012 Guillaume Dollé, Vincent Mazet (LSIIT, CNRS/Université de Strasbourg)
+// Licence: GNU General Public License Version 2
+// see http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
+//
+// Depends: LibGSL
+// OS: Unix based system
+
+
+#include <iostream>
+#include <gsl/gsl_rng.h>
+
+#include "rtnorm.hpp"
+
+
+int main()
+{
+ double a = 1; // Left bound
+ double b = 9; // Right bound
+ double mu = 2; // Mean
+ double sigma = 3; // Standard deviation
+ std::pair<double, double> s; // Output argument of rtnorm
+ int K = 1e5; // Number of random variables to generate
+
+ //--- GSL random init ---
+ gsl_rng_env_setup(); // Read variable environnement
+ const gsl_rng_type* type = gsl_rng_default; // Default algorithm 'twister'
+ gsl_rng *gen = gsl_rng_alloc (type); // Rand generator allocation
+
+ //--- generate and display the random numbers ---
+ //std::cout<<"# x p(x)"<<std::endl;
+ std::cout<<a<<" "<<b<<std::endl;
+ std::cout<<mu<<" "<<sigma<<std::endl;
+ for(int k=0; k<K; k++)
+ {
+ s = rtnorm(gen,a,b,mu,sigma);
+ std::cout<<s.first<<" "<<s.second<<std::endl;
+ }
+
+ gsl_rng_free(gen); // GSL rand generator deallocation
+
+ return 0;
+}
+