Posted: Mar 10, 2012 5:26 am
by mizvekov
By the way, since we were talking about cool new c++ features, here is another one of my favorites:
Example code of the new random number library, much more powerful and modular:
Code: Select all
// 1.0 is the lambda parameter of the exponential distribution
auto random = std::bind(std::exponential_distribution<double>(1.0), std::default_random_engine());
for (;;)
      std::cout << random() << std::endl;

Will generate numbers like:
Code: Select all
0.330217
3.44907
0.208902
1.28924
0.838482
0.549105
0.0226059

Pretty hard to beat that in elegance :grin:
The modular design means that you can use other generators, like the other pseudo-random ones included in the standard lib, or roll your own, be that another pseudogen, or even one based on reading /dev/random (for unix systems) or which communicates directly with a hardware RNG.
And you can combine any of those with any probability distribution, such as the ones included in the standard (there are several others, like uniform, normal, binomial), or again, create your own.

Pretty neat huh? :grin: