Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

2
  • Couldn't you create a helper function that you use instead that prevents concurrent access to rand using locks or something? Commented Oct 19, 2018 at 0:35
  • 1
    Be careful with this. Threads are likely to call the rand function in different orders, so even if rand is thread safe, if the order of the random numbers matters then the only thing you can do is make sure all your operations are ordered. You can still do things in parallel, but you'll have to add a lot of synchronization and you'll end up spending a lot more time blocking. If this is about trying to verify your implementation, you may want to consider hashing based on position, or generating an array of G->N random numbers ahead of time then using arr[j] instead of rand(). Commented Oct 19, 2018 at 2:03