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 7559379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:37:13+00:00 2026-05-30T12:37:13+00:00

This is a very general question that is mostly just conceptual. I was thinking

  • 0

This is a very general question that is mostly just conceptual. I was thinking about testing the random number generator to see its effectiveness at following a uniform distribution over some x values (ex 6 for a dice roll). Doing this in a simple loop is how I have it now, but I was thinking about multithreading the simulation.

I was wondering if this would give me any speedup since I would only have one random number generator shared between all threads with semaphore protection (needed to ensure no two threads access and generate random numbers at the same time meaning duplication of results).

Since each thread would hardly have other operations (just if statements for checking and incrementing x) would threading it even give me faster results, or will the dependency on one random number generator mean it would be essentially the same as a single thread?

  • 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-05-30T12:37:15+00:00Added an answer on May 30, 2026 at 12:37 pm

    In theory you should see an increase in performance, at least until the number of threads equals the number of cores in use. However, in reality, you’ll be adding code (and therefore execution time) to handle the multithreading infrastructure, and if the bulk of each thread’s time is spent waiting for a slow RNG you may see a decrease in performance.

    On the other hand, you may be able to improve performance with some cleverness. For example, you might have one task dedicated to generating random numbers, and if you’re only looking for values from 1 to 6, you may be able to generate more than one value from each result from the RNG. You could put those values into a queue and let the other tasks read from the queue. Of course, you’d have to be careful that your optimizations don’t alter the distribution of the RNG.

    Unless the idea of counting execution cycles excites you, the best way to find your answer is by trying it. And it’s always educational to use a profiler to find out where most of the time is spent–this is notoriously difficult for humans to get right through intuition alone, and even experienced developers are often surprised by the results.

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

Sidebar

Related Questions

Just a very general question, that not only applies to this example. Let's say
This is a very general question that's not related to a specific language. I'm
This is a very general question: I was wondering whether it is possible to
Important : Please see this very much related question: Return multiple values in C++
This is a very general question but it's based on a specific problem. I've
This is a very general question, but here goes: I'm trying to create a
This is a very general and noob question, but I am a noob with
This is not a theoretical or general question about when to use pass by
Although this is a very general question, here's my specific example so you can
There is a similar question to this but answer is very general, vague.( Detecting

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.