How to generate real random number from normal distribution

I want to generate random numbers of normal distribution and use scentence like
1
2
3
4
 
std::default_random_engine generator;    
std::normal_distribution<double> distribution(0,1);
arrayX[i][j]=distribution(generator);


But I find that each time the array I got are the same. So how should I generate random numbers with different seedings with normal distribution?

Thanks for your attention.
But I find that each time the array I got are the same.

That's because your using same (default) seed for 'generator'.

Either pass a seed to the constructor, or call the seed() method directly. e.g. (to seed using time)

std::default_random_engine generator(time(0));

or

1
2
default_random_engine generator;
generator.seed(time(0));


Andy
Last edited on
Topic archived. No new replies allowed.