Simple random numbers using std::random

/
0 Comments
Another of the great things added in C++11 was the random library. It provides a bunch of facilities to create random numbers, way better than the C rand().
As it happens a lot of time, its use is cumbersome, compared to the good old rand(). As I use a lot of random numbers in my code, I came up with a couple templates that make life easier, and which I'm sharing today:
As a side note, the min and max limit are inclusive. 

Random integer from 1 to 9:
randNatural<int>(1,9);

Random double from 0 to 1:
randReal<double>(0,1);



You may also like

No comments:

Pages

Powered by Blogger.