std::uniform_real_distribution and rand()
c++, random
Solution
The real comparison is between `rand` and one of the random number engines provided by the C++11 standard library. `std::uniform_real_distribution` just distributes the output of an engine according to some parameters (for example, real values between 10 and 20). You could just as well make an engine that uses `rand` behind the scenes.
Now the difference between the standard library random number engines and using plain old `rand` is in guarantee and flexibility. `rand` provides no guarantee for the quality of the random numbers - in fact, many implementations have shortcomings in their distribution and period. If you want some high quality random numbers, `rand` just won't do. However, the quality of the random number engines is defined by their algorithms. When you use `std::mt19937`, you know exactly what you're getting from this thoroughly tested and analysed algorithm. Different engines have different qualities that you may prefer (space efficiency, time efficiency, etc.) and are all configurable.
This is not to say you should use `rand` when you don't care too much. You might as well just start using the random number generation facilities from C++11 right away. There's no downside.
Problem
Why is `std::uniform_real_distribution` better than `rand()` as the random number generator? Can someone give an example please?