Scientific random normal distribution

Hello,

I would like to create a series of random normal distribution for statistical purpose.

I tried with a basic method: http://www.cplusplus.com/reference/random/normal_distribution/
which gives each times the same series.

Some people said, even with seed of system time, the generated series is not random enough for statistical usage.

Could anyone please give me an indication to do it in an appropriate way?

Thanks in advance.
Please show us the code that gives identical series on each run.
OK, here is the code to generate.

1
2
3
4
5
6
7
	const int nrolls=100;
	double eps[nrolls]={};

	default_random_engine generator;
	normal_distribution<double> distribution(0,1);
	for(int i=0; i<nrolls; i++)
		eps[i]=distribution(generator);


Each time I run the program it gives exactly the same series of normal distribution...
Thanks for your help!
It is true that the pseudo-random numbers are not random enough for some very specific applications, but for most practical purposes they are good enough. I know people that work in stochastic physics and that use pseudo random numbers all the time to generate many realizations of random variables with the normal random number generator, without any problem.

I found this
http://www.fourmilab.ch/hotbits/
on the net which seems to be a nice way of getting true random numbers.
1
2
3
4
5
6
7
8
    const int nrolls=100;
    double eps[nrolls]={};

    std::random_device seed_generator ;
    default_random_engine generator(seed_generator());
    normal_distribution<double> distribution(0,1);
    for(int i=0; i<nrolls; i++)
        eps[i]=distribution(generator);
Last edited on
Thanks ljs for your tips. I have checked the website. Very interesting and powerful generator. However, they only supply random numbers online. There is no program of generating to do it on my laptop.

Thanks cire for your help. It works, and it seems give random numbers. For a scientific (statistical) usage, do you think these numbers are reliable enough? I really don't know about this point and I am interested to know it...
The type of the default generator is implementation defined, so it's hard to say exactly what the quality of the results will be, but you can specify one of the pre-defined generators so that you know what you're getting. As to whether they may be "random" enough for your purposes, that's something you'll have to decide based on the algorithms involved.

http://en.cppreference.com/w/cpp/numeric/random
Thanks a lot cire for your precise explanation! I will check the details of the link.
Last edited on
Topic archived. No new replies allowed.