[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppBoostRandom
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppBoostRandom
(C++) (Boost C++ library) random
Boost C++ library for calculating random numbers.How to: get a random number from a normal distribution?
int main() { const double mean = 10.0; const double sigma = 1.0; boost::normal_distribution<double> norm_dist(mean, sigma); boost::lagged_fibonacci19937 engine; //Make a histogram const int size = static_cast<int>(mean) * 2; std::vector<int> histo(size,0); for (int i=0; i<1000000; ++i) { const double value = norm_dist.operator () <boost::lagged_fibonacci19937>((engine)); int index = value; index = (index < 0 ? 0 : index); index = (index > size - 1 ? size - 1 : index); ++histo[index]; } //Output histogram for (int i=0; i<size; ++i) { std::cout << histo[i] << std::endl; } return 0; }
- include <boost/random/normal_distribution.hpp>
- include <boost/random/lagged_fibonacci.hpp>
- include <iostream>
- include <vector>
Code links
- ::, scope operator
- <<, stream out operator
- #include
- char
- cout
- endl
- for
- int
- iostream
- main
- return
- scope operator, ::
- std
- stream out operator, <<
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
