This is a follow up question on an answer on this page:
How to generate random double numbers with high precision in C++?
#include <iostream>
#include <random>
#include <iomanip>
int main()
{
std::random_device rd;
std::mt19937 e2(rd());
std::uniform_real_distribution<> dist(1, 10);
for( int i = 0 ; i < 10; ++i )
{
std::cout << std::fixed << std::setprecision(10) << dist(e2) << std::endl ;
}
return 0 ;
}
The answer works fine but I had a hard time to realize how to put the output of this code in a double variable instead of printing it to stdout
. Can anyone help with this?
Thanks.