C++11 random library

I have come across the random library and would like to use it to generate pseudo-random numbers in my C++ program.

However, the PGI C++ compiler can’t seem to find it. Searching for “random.h” doesn’t return any file in the compiler’s directory. Is it possible to use this library with the PGI C++ compiler? If not, what other method can I use?

Hi,

C++11 support for random already exists in PGI. Try this example:

#include <tr1/random>
#include <iostream>

int main()
{
  std::tr1::minstd_rand gen;
  gen.seed((unsigned int)time(NULL));
  for(int i = 0; i < 10; ++i){
    std::cout << gen() << " ";
  }
  std::cout << std::endl;
}

Note that you will need to be on a Linux system with GCC 4.7 or later to have runtime support for this.

Thanks,

+chris