Generating parallel random numbers in a thread-safe way and using them in computations implemented by class method I have the following code that I managed to make thread-safe but I am not sure if I am using C++ technology optimally.

#include &lt;iostream&gt;
#include &lt;omp.h&gt;
//#include &lt;memory&gt;

class GenNo
{
public:

    int num;

    explicit GenNo(int num_)
    {
        num = num_;
    };

    void create(int incr)
    {
        num += incr;
    }
};

class HelpCrunch{
public:
    HelpCrunch() {

    }

    void helper(int number)
    {
        std::cout &lt;&lt; "Seed is " &lt;&lt; number &lt;&lt; " for thread number: " &lt;&lt; omp_get_thread_num() &lt;&lt; std::endl;
    }
};

class calculate : public HelpCrunch
{
public:

    int specific_seed;
    bool first_run;

    void CrunchManyNos()
    {
        HelpCrunch solver;

        thread_local static GenNo RanNo(specific_seed);
        //std::unique_ptr&lt;GenNo&gt; GenNo_ptr(nullptr);
        /*
        if(first_run == true)
        {
            GenNo_ptr.reset(new GenNo(specific_seed));
            first_run = false;
        }
         solver.helper(GenNo_ptr-&gt;num);
*/
        RanNo.create(1);
        solver.helper(RanNo.num);



        //do actual things that I hope are useful.
    };
};




int main()
{

    calculate MyLargeProb;
    MyLargeProb.first_run = true;

#pragma omp parallel firstprivate(MyLargeProb)
    {
        int thread_specific_seed = omp_get_thread_num();
        MyLargeProb.specific_seed = thread_specific_seed;

        #pragma omp for
        for(int i = 0; i &lt; 10; i++)
        {
            MyLargeProb.CrunchManyNos();
            std::cout &lt;&lt; "Current iteration is " &lt;&lt; i &lt;&lt; std::endl;
        }

    }
    return 0;
}


The code that is commented out can be used as an alternative but the pointer gets destroyed after the method finishes which crashes the programme. Moreover, it was pointed out to me that I could use threadprivate for the static instance of GenNo. The use case equivalent of GenNo is a random number generator that gets seeded once per thread with a known seed and then is left alone, i.e. not reinitialised, but called upon to generate fresh random numbers in each iteration.

I know the whole structure seems a bit contrived but my hands are tied somewhat: the classes and their dependence are dictated to me by the tools I would like to use and I think this scenario is common in the scientific computing community. 
It compiles fine and upon manual testing appears to be thread-safe and working but again, I don't think this is particularly good style and a bit cobbled together, so I would love to hear everyone's comments.
Important note: I am using gcc as my compiler and gcc for over ten years now doesn't support threadprivate class instances. Intel's compiler which can be obtained for academics and students on a trial license, does.

The following is an example of code that would not compile in GCC (even the most recent version).

#include "myclass.h"
#include &lt;omp.h&gt;
int main 

{
   myclass myinstance;
   #pragma omp parallel threadprivate(my_instance)

    {

      // do parallel things

     }
    return 0;
}


The error message would be my_instance declared threadprivate after first use which is a long-standing bug or rather not a bug but a missing feature, see here, for example.
what is the problem with just creating a range of random number generators from &lt;random&gt; and assign each to a thread? 

Mind that using thread_local might not be a good way, as initialization of random number generators is costly. Also i do not know, how therngs would be seeded in a thread_local environement.