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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:06:18+00:00 2026-05-28T20:06:18+00:00

I have been playing with Boost.Random for a day now, and while boost::uniform_int_distribution<> works

  • 0

I have been playing with Boost.Random for a day now, and while boost::uniform_int_distribution<> works well, I am having trouble with boost::exponential_distribution<>.

A simple program is worth a thousand words:

#include <iostream>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/exponential_distribution.hpp>

int main() {
  boost::mt19937 gen;
  boost::exponential_distribution<> dis;
  std::cout << dis(gen) << "\n";
  return 0;
}

Compiled with Clang 3.0, using Boost 1.39.1 (no, I cannot upgrade Boost).

The output is invariably the same: nan.

I could not find any reported issue so I guess it’s me not using the library correctly… Any clue would be 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-28T20:06:20+00:00Added an answer on May 28, 2026 at 8:06 pm

    Given a random number r, uniformly distributed on [0,1), -log(r) is distributed on (0,infinity) with the distribution exp(-x).
    The former is boost::uniform_01().

    If you need a distribution p exp(-px), then it’s -(1/p)log(r).

    In both cases here log(x) is a natural log (base e).

    UPD: Using boost::variate_generator seems to work for me (boost 1.43):

    #include <iostream>
    #include<boost/random.hpp>
    
    int main() {
      boost::mt19937 rng(11u); 
      boost::variate_generator< boost::mt19937&, boost::exponential_distribution<> > rndm(rng, boost::exponential_distribution<>()) ;
      std::cout<<rndm()<<"\n";
    }
    

    I did not check the distribution though.

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

Sidebar

Related Questions

I have been playing around with GTK since a couple of days now,while going
I have been playing with this for a while, but the closest I have
I have been playing around with the postgresql.conf file for a couple days now.
I have been playing around a bit with a fairly simple, home-made search engine,
I have been playing around with jQuery for a bit now, and am really
I have been playing around with writing some simple card games in Python for
I have been playing around with silverlight for a couple of days now and
I've been playing around with boost::spirit::qi lately and have been trying to write my
I have been playing around with JavaScript and Canvas for a while. Very often
I have been playing around with Umbraco 5 for some days now. I have

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.