Dear Éric,
interesting question.
At first I thought: What random number genererator are you using? It seems
that the Mersenne Twister is standard but there are several others.
Second, have you tried out the random engine of C++11:
http://www.cplusplus.com/reference/random/
I appended a minimal example.
Best wishes and keep us informed. :)
-- Klaus.
> Dear all,
>
> I wonder how to generate random vectors with GSL.
> I'm aware of the *gsl_ran_dir_nd *routine but the numbers are normalized.
> I need to generate random velocities for a given temperature of N
> particles.
> I currently call *gsl_ran_gaussian* 3N times.
> That's too expensive.
> I'd like to generate a 3N vector at once.
> Is there anyway to do this with GSL?
>
> Thanks,
>
> Éric.
>
> --
> Éric Germaneau (???), Specialist
> Center for High Performance Computing
> Shanghai Jiao Tong University
> Room 205 Network Center, 800 Dongchuan Road, Shanghai 200240 China
> M:[email protected] P:+86-136-4161-6480 W:http://hpc.sjtu.edu.cn
>
#include <iostream>
#include <random>
class RNG{
public:
RNG():_engine( 42 ), _distribution( 0.0, 1.0 ) {}
auto operator()() -> double { return _distribution( _engine ); }
private:
std::mt19937 _engine;
std::normal_distribution<double> _distribution;
};
int main()
{
RNG rng;
unsigned int const N = 1000;
for(unsigned int i = 0; i < N; ++i)
std::cout << rng() << std::endl;
return 0;
}