I know of many examples of commercial products that use incorrect methods for getting random numbers. It's a shame that some companies still use rand()
in cryptography and banking software.
Let's see how to get a fully random uniform distribution using Boost.Random
that is suitable for banking software.
Basic knowledge of C++ is required for this recipe. Knowledge about different types of distributions will also be helpful. The code in this recipe requires linking against the boost_random
library.
To create a true random number, we need some help from the operating system or processor. This is how it can be done using Boost:
- We need to include the following headers:
#include <boost/config.hpp> #include <boost/random/random_device.hpp> #include <boost/random/uniform_int_distribution.hpp>
- Advanced random bits providers have different names under different platforms:
int main() { static const std::string provider...