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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:24:18+00:00 2026-05-20T08:24:18+00:00

I’m trying to maintain separate random seeds for different clients (from server app). random_r/srandom_r(linux

  • 0

I’m trying to maintain separate random seeds for different clients (from server app).
random_r/srandom_r(linux api) can’t be used because the code must compile both on mac/linux.

It seems I could use boost::random instead of random_r/srandom_r.

I’ve tried defining my random function(which is class member function) and supply the function to random_shuffle’s 3rd parameter.

random_shuffle( RandomAccessIterator first, RandomAccessIterator last,
                        RandomNumberGenerator& rand );


ptrdiff_t MyClass::_MyRandom(ptrdiff_t i)
{
    int result;

    boost::uniform_int<> numberInterval( 1, 10000);
    boost::variate_generator< RNGType, boost::uniform_int<> >
        dice(mRng, numberInterval); // mRng is boost::mt19937 type instance variable

    result = dice();
    //  random_r(mRandomData, &result);                                                                                                                                                                                                                                       
    result = result % i;

    return result;
}

what’s the proper form of bind() here?

mRng.seed(mRandomSeed); //mRandomSeed will be different for different clients.
//I'm trying to random_shuffle a vector with the random seed.
random_shuffle(v.begin(), v.end(), boost::bind(&MyClass::_MyRandom, _1));

Being not so familiar with boost::random boost::bind, i’m not so sure if my approach is going to work.
Any comment on direction would be also appreciated.

  • 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-20T08:24:19+00:00Added an answer on May 20, 2026 at 8:24 am

    There is some code that does what you want here.
    This previous SO question has simpler code, but uses a function pointer instead of a function object, which will not be as efficient. Here is some (not tested) code to try as the last argument to random_shuffle:

    template <typename Gen>
    struct shuffle_wrapper {
      Gen& gen;
      shuffle_wrapper(Gen& gen): gen(gen) {}
      int operator()(int r) const {return boost::uniform_int<>()(gen, r);}
    };
    
    shuffle_wrapper<`your generator type`>(`your generator`)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.