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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:24:21+00:00 2026-06-05T16:24:21+00:00

I am trying to use the C++11 approach to random number generation: #include <random>

  • 0

I am trying to use the C++11 approach to random number generation:

#include <random>
#include <functional>
#include <iostream>

int main(int argc, char *argv[])
{    
    std::normal_distribution<double> normal(0, 1);
    std::mt19937 engine; // Mersenne twister MT19937
    auto generator = std::bind(normal, engine);

    int size = 2;

    engine.seed(0);
    normal.reset();
    for (int i = 0; i < size; ++i)
        std::cout << generator() << std::endl;

    std::cout << std::endl;

    engine.seed(1);
    normal.reset();
    for (int i = 0; i < size; ++i)
        std::cout << generator() << std::endl;

    std::cout << std::endl;

    engine.seed(0);
    normal.reset();
    for (int i = 0; i < size; ++i)
        std::cout << generator() << std::endl;

    return 0;
}

The output is:

0.13453
-0.146382

0.46065
-1.87138

0.163712
-0.214253

That means that the first and the third sequence are not identical even if they are seeded with the same number. Please, what am I doing wrong? Is the

std::normal_distribution<double>

Just a function in the mathematical sense (produces y out of x deterministically) or am I missing something? If it is just a function, what does the reset method actually do?

  • 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-05T16:24:25+00:00Added an answer on June 5, 2026 at 4:24 pm

    You are binding the engine and the distribution, such the following calls on reset won’t affect the bound function.

    The solution is to bind references to the engine and the distro

    auto generator = std::bind(std::ref(normal), std::ref(engine));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the stock standard win32com approach to drive Excel 2007
I'm trying to use a WSDL Top Down approach to create a Web Service
What's an effective approach to debug NameErrors in Rails? I'm trying to use the
I am trying to get a random row in MySQL. Here is my approach:
Im trying to use this approach. My app is a cms. I have admins,
I'm trying to use brownian motion to create a group of random moving particles.
I'm trying to use NPR approach of streaming audio using the StreamProxy and PlaybackService
I am currently trying to use the new approach of using FlexGlobals to access
I am trying to use some C code in Unity3D pro. My basic approach
I was trying use a set of filter functions to run the appropriate routine,

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.