About Normal distribution

I am generating random number of normal distribution (0,1) but i suspect maybe I have done it wrong. The generator I use right now is

std::random_device rd;
std::mt19937 gen(rd());
std::default_random_engine generator;
std::normal_distribution<double> distribution(0,1);

Am I doing the right thing? Any suggestion whether this is a real random number generator?
The code that you have written compiles. srand(time(0)) is only useful if you are going to call rand(). To generate a random number using the generator and the distribution you can do distribution(generator).
Can you provide detailed info how to use distribution(generator)?
I wanna get a double number from this normal distribution in every step of the program.

Thanks so much.
hi, there is an example here:

in short, to get numbers from a distribution you do

double number = distribution(generator);
You have defined two random generators gen and generator. One is probably enough.

Both generators can be used in the same way.
std::cout << "Random number: " << distribution(generator) << std::endl;
std::cout << "Random number: " << distribution(gen) << std::endl;
Topic archived. No new replies allowed.