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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:16:49+00:00 2026-05-11T14:16:49+00:00

I have a simple wrapper for an Mersenne twister random number generator. The purpose

  • 0

I have a simple wrapper for an Mersenne twister random number generator. The purpose is to scale the number returned by the generator (between 0 and 1) to between argument defined limits (begin and end).

So my function is

inline float xlRandomFloat(float begin, float end) {return (begin+((end-begin)*genrand_real2()));} 

I don’t believe the implementation of genrand_real2() function is important, but if I am wrong it can be found here

The problem is the function does not return the translated result. The scaling (multiplying by (begin-end) seems to work correctly, but the addition of begin does not seem to be returned.

So if I call xlRandomFloat(5,10) – I get values between 0 and 5.

If I debug with GDB, and use the print function then it shows the correct result. So then I tried separating things into lines to see what happens

inline float xlRandomFloat(float begin, float end) {     float ret;     ret=(((end-begin)*genrand_real2()));     ret+=begin;     return ret;}; 

When debugging, it jumped straight from the first line into the genrand_real2() function and skipped out every thing else entirely. That was really confusing so I thought it may have something to do with the inlining. I moved the file from this .hpp file to the .cpp and removed the inline keyword and everything works correctly.

But why does this behavior occur, and how can I inline this function? Also, I am not sure if this is relevant, but often when I made changes to the sources, my Make compilation would say there is nothing to be done. Which is unusual since normally I expect make to pick up on changes in the sources and rebuild accordingly.

Any ideas.

Thanks

Zenna

  • 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. 2026-05-11T14:16:50+00:00Added an answer on May 11, 2026 at 2:16 pm

    Okay, several things at work here.

    First, on the debugging, you describe what I’d think of as the more or less expected behavior, because when you inline a function, there’s no generated code to go with the fromt matter of the function. So, the first statement there is

    ret=(((end-begin)*genrand_real2())); 

    and the first step on that is to call genrand_real2(). If genrand_real2() is also inline, then you end up at the first statement in that, with no pause to catch your breath.

    Second, make sure you’re really running the code you think you are. Try making from a clean directory –some C++ compilers make precompiled pieces that they preserve to speed compilation. Make sure your inline definition has been completely removes or commented out from the header files. m

    Thrd, make a very simple program with an inline and make sure it’s behaving as you expect.

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

Sidebar

Related Questions

I have simple class with width and height member fields which define number of
I have a Delphi application that I have written a fairly simple wrapper .exe
I currently have a simple model defined, with a photoupload feature using django thumbnails
I have an EntityId class that servers as a simple wrapper class to database
I am making a simple wrapper for a c library that needs to have
I have this very simple wrapper template: template<class T> struct wrapper { inline operator
I have a simple contact form: <div class=contact-wrapper> <div class=grid_8 contact-form-wrapper> <form id=contactus method=GET
I have a simple struct Wrapper , distinguished by two templated assignment operator overloads:
I have written a simple OCI wrapper class in PHP which uses persistent connections
I have a simple mysqli wrapper class I use for my database operations. I

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.