Exponential distribution is there to generate a random number following a certain distribution.
To use exponential distribution, you do something like that:
#include <iostream>
#include <boost/random.hpp>
int main() {
boost::mt19937 seed(5u);
boost::variate_generator<boost::mt19937&, boost::exponential_distribution<>> random_n(seed, boost::exponential_distribution<>()) ;
cout << random_n() << endl; return 0;
}
Now, I suspect you want to do something but it is not so clear for me. You want to sort or whatever? Pick a random number in your vector?
Edit:
OK. In brief and short, even if you have access to C++11 you cannot go very far. Most of the random generator are now in the standard. But not the PDF. If you are curious about why: here it is: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1398.html.
So you definitly need the boost.math toolkit, this is your only way to compute your PDF. Here is some sample code for you:
#include <boost/math/distributions/exponential.hpp>
int main() {
const auto lbda = 1.0;
const auto d = exponential_distribution<> { lbda };
cout << pdf(d, 0) << endl; // e(0) = 1
cout << pdf(d, 1) << endl; // e(-1) = 0.3678
return 0;
}
In short: for using boost PDF
, you do not need per se the vector cause the PDF function knows how to compute its distribution.
Edit 2: So if you need to populate a vector with some distribution, you can simply use std::generate
and apply the distribution to it, here is an example with a std::exponential_distribution
(c++11, but you can use boost).
std::vector<float> v(20);
random_device rd;
mt19937_64 gen(rd());
exponential_distribution<float> dis(1);
auto rand = bind(dis, gen);
generate(begin(v), end(v), rand);
for (auto& e : v) cout << e << endl;
The code I am showing here is filling a vector
of 20 elements with an exponential distribution. You can switch to an std::array
, change the float to whatever you need, increase the size of the vector or array.
You can also take a look at this old C++ library (nowaday a pytonic one) which does what you need : http://myfitter.hepforge.org/. This is probably your best bet. It uses a non parametric method. The C++ version is quite old and I am not so sure fully functional but perhaps this will go for you.