-
-
Save seiriosPlus/e3de8370195373a2f4cb8303773d4047 to your computer and use it in GitHub Desktop.
boost random distribution usage sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <boost/function.hpp> | |
#include <boost/bind.hpp> | |
#include <boost/random/mersenne_twister.hpp> | |
#include <boost/random/uniform_real_distribution.hpp> | |
#include <boost/random/normal_distribution.hpp> | |
int main(int argc, char* argv[]) | |
{ | |
size_t seed = 1234567890; | |
boost::random::mt19937 engine(seed); | |
boost::function<double()> randu = | |
boost::bind(boost::random::uniform_real_distribution<>(0, 1), engine); | |
std::cout << "sampling 100 from uniform distribution" << std::endl; | |
for (size_t i = 0; i < 100; ++i) { | |
std::cout << randu() << std::endl; | |
} | |
boost::function<double()> randn = | |
boost::bind(boost::random::normal_distribution<>(0, 1), engine); | |
std::cout << "sampling 100 from normal distribution" << std::endl; | |
for (size_t i = 0; i < 100; ++i) { | |
std::cout << randn() << std::endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment