Tutorial or sample code for C ++ 11 extension with generators and distributions

I have inherited C ++ code that I wrote to create uniform random numbers and a Gaussian distribution. He runs the algorithms of Dr. George Marsaglia very quickly. (I used them to generate storytelling samples for the arrogant Monte Carlo integration.)

I think it would be nice to regroup the generator and distribution to work with the new std :: random C ++ 11 scheme.

Can someone point me to a tutorial or a good link for std :: random, which includes the necessary information on how to expand it? Sample code would be perfect.

UPDATE Thanks for helping everyone. Now I have written a replacement for std :: normal_distribution, which comes with Visual C ++ 2010. On my machine, the replacement is 26% higher if it is loaded with the default engine. I'm a little disappointed that the difference is no bigger, but hey, what is my problem. :-)

+8
c ++ random c ++ 11 stl visual-studio-2010
source share
2 answers

N3376 is the latest draft of the C ++ standard (this is a C ++ 11 post, but this is a great C ++ 11 snapshot).

All C ++ 11-random is in: 26.5 Random Number Generation [rand]

26.5.1.4 The random number engine requirements [rand.req.eng] have all the requirements that your random number generator must fulfill.

26.5.1.6. The random number distribution requirements [rand.req.dist] have all the requirements that your Gaussian distribution needs to fulfill.

26.5.8.5.1 The class template normal_distribution [rand.dist.norm.normal] is a section describing the std-specified Gaussian distribution.

The C ++ 11 <random> very similar to STL because it sets the requirements for random number generators (containers) and random distributions (algorithms), and then the client can mix and match them. This is really a very cool design.

Sorry, I do not know a good textbook. The C ++ standard is a great reference and a lousy tutorial. However, you are obviously well educated in the field of random numbers. Therefore, assuming you know something about C ++, the C ++ standard might not be too bad.

Open source <random> options are available if you want to view their source (for example). One example is libC ++ . All they ask for is that you retain your copyright notices if you reuse any of their code.

Edit

You are uniquely qualified to write this lesson. :-)

+5
source share

You can learn a lot by reading the sources of the extended library, as many C ++ 11 suggestions were adopted from boost.

See the rng interface interface here:

http://en.cppreference.com/w/cpp/numeric/random/mersenne_twister_engine

I would start by implementing the min max seed and operator () functions to see if it passes as a valid engine for C ++ 11

+1
source share

All Articles