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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:38:13+00:00 2026-06-07T17:38:13+00:00

I am trying to get real random values using boost::random libraries. This is my

  • 0

I am trying to get real random values using boost::random libraries. This is my code:

#include <iostream>

#include <boost/random/uniform_real_distribution.hpp>
#include <boost/random/mersenne_twister.hpp>

boost::random::mt19937 eng = boost::random::mt19937();
boost::random::uniform_real_distribution<double> urd =
   boost::random::uniform_real_distribution<double>(0,20);

for (int i = 0; i <= 100; i++)
   std::cout << urd(eng) << std::endl;

But I get integer numbers between 0 and 20.

How can I do?

I also tried another engine:

#include <iostream>

#include <boost/random/uniform_real_distribution.hpp>
#include <boost/random/lagged_fibonacci.hpp>

boost::random::lagged_fibonacci607 eng = boost::random::lagged_fibonacci607();
boost::random::uniform_real_distribution<double> urd =
   boost::random::uniform_real_distribution<double>(0,20);

for (int i = 0; i <= 100; i++)
   std::cout << urd(eng) << std::endl;

But nothing… (always integer values)

  • 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-07T17:38:14+00:00Added an answer on June 7, 2026 at 5:38 pm

    How about setting the precision before you output? std::cout.precision(15);?

    Or use:

    std::cout.precision(std::numeric_limits<double>::digits10);
    

    Example

    #include <iostream>
    #include <limits>
    #include <boost/random/uniform_real_distribution.hpp>
    #include <boost/random/mersenne_twister.hpp>
    
    int main()
    {
        boost::random::mt19937 eng = boost::random::mt19937();
        boost::random::uniform_real_distribution<double> urd =
        boost::random::uniform_real_distribution<double>(0,20);
    
        std::cout.precision(std::numeric_limits<double>::digits10);
        for (int i = 0; i <= 100; i++)
        {
           std::cout << urd(eng) << std::endl;
        }
    }
    

    The default precision for std::cout is set at 6, so it should work without setting this, but…

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

Sidebar

Related Questions

I've been trying to get this code to work for hours! All I need
Any real world simple samples of using abstract class? I'm trying to get in
I'm trying to get a real equivalent for Java's public static final in Scala
I've been having real problems trying to get a ruby script to run through
I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
I am trying get Struts 2 and Tiles to work and I am using
Trying to get this expression to work, can someone look at it and tell
i am having a issue with treeview liststore trying to get a real-time update,
I'm trying to get some code compiled under gfortran that compiles fine under g77.

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.