Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:27:24+00:00 2026-06-01T14:27:24+00:00

I am parallelizing calls to newSeed() and rand(),static member functions of class Random. newSeed()

  • 0

I am parallelizing calls to newSeed() and rand(),static member functions of class Random. newSeed() feeds a static member of class Random (let’s call it seed). To be more concrete, I parallelize calls to this function in another class, the Method class:

 double* Method::randomPoint(double* bottom_, double* top_ )
 {
try{
    Random generator_ ;

    double* pt_ = new double[m_ndim];

    generator_.newSeed();
    for(int i=0;i<m_ndim;i++)
    {
        pt_[i]= generator_.rand(bottom_[i],top_[i]);
    }

    return pt_;

}
catch(...)
{
     return NULL;
}
 }

To sum up, in each parallelized call, I create a new instance of class Random, I call newSeed() and rand() method in this object. Since newSeed() is called on a given instance, I hope that newSeed() initializes the seed member for this object – and thus for this thread only. Since seed is static and newSeed() is static as well, am I modifying seed for ALL currently running instances of Random class (and for all threads)?

Please tell me if question must be clarified.

Thanks and regards.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:27:25+00:00Added an answer on June 1, 2026 at 2:27 pm

    The static fields are shared amongst ALL the instance of the class of the process.
    Also, the threads are running in the same process, meaning that are sharing the memory, using the same classes

    So, if you modify the static field seed, all of the “Random” instances in all of your threads will have the modification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am wondering whether this could be worse parallelizing generation of random numbers. I
I'm currently parallelizing program using openmp on a 4-core phenom2. However I noticed that
I have a foreach loop that I am parallelizing and I noticed something odd.
I have a sum that I'm trying to compute, and I'm having difficulty parallelizing
Based on your experience, have you gained performance boost from parallelizing disk I/O? I/O
So I'm having a little trouble figuring out the best way parallelizing these for
I am trying to make my_class thread-safe like so. class my_class { const std::vector<double>&
How do you figure out whether it's worth parallelizing a particular code block based
I have seen a concept called Parallelizing Table Creation in oracle and I'm not
I'm trying to learn how to use OpenMP by parallelizing a monte carlo code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.