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

  • Home
  • SEARCH
  • 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 8672471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:12:45+00:00 2026-06-12T19:12:45+00:00

So I have multiple threads which will be using the rand_r function. The signature

  • 0

So I have multiple threads which will be using the rand_r function. The signature of this function is :

int rand_r(int *val);

I was trying to use the time to seed this function but I’m having all kinds of trouble. Could anyone explain to me how I would call rand_r using time, or some other simple way to seed rand_r dynamically.

Thanks!

  • 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-12T19:12:46+00:00Added an answer on June 12, 2026 at 7:12 pm

    For the reentrant version rand_r, the seed is just the initial value of the state .You need one seed per thread. Either create an array of seeds, or make the seed variable thread-local:

    _Thread_local unsigned int seed = time(NULL);
    
    int do_stuff()
    {
        for ( ; ; )
        {
            int n = rand_r(&seed);
            // use n
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which runs multiple threads. I use MadExcept to catch errors
I have a counter variable which will be accessed by multiple threads which will
I have an object (Client * client) which starts multiple threads to handle various
I have multiple threads that share use of a semaphore. Thread A holds the
I'm using Posix Message Queues on Linux. Basically, I have multiple threads that receive
The problem is this: I have multiple competing threads (100+) that need to access
Using POSIX threads & C++, I have an Insert operation which can only be
I have a simple method which is called from multiple threads; @Override public Bitmap
I have multiple threads who all need to write to the same Dictionary. I
I have multiple threads each one with its own private concurrent queue and all

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.