Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use C++11 standard library to generate random numbers #715

Merged
merged 5 commits into from
Sep 10, 2022

Conversation

bcoconni
Copy link
Member

@bcoconni bcoconni commented Sep 4, 2022

This PR addresses issue #666 and allows removing the static method FGJSBBase::GaussianRandomNumber and its static member gaussian_random_number_phase.

The method FGJSBBase::GaussianRandomNumber is replaced by the C++ standard library class std::normal_distribution and all the other calls to the system function rand() have been replaced by the C++ standard library class std::uniform_real_distribution. The purpose of that is to use the same random number generator for both the gaussian and uniform distributions.

A new class JSBSim::RandomNumberGenerator has been created to centralize the random seed value and make sure all the random generators in JSBSim are referring to the same instance of RandomNumberGenerator so that calling FGFDMExec::Srand() (or setting the property simulation/randomseed) has a global effect over JSBSim random number generation.

There are 2 exceptions to this behavior:

  1. The method FGFunction::makeRandomEngine which allows using specific instances of JSBSim::RandomNumberGenerator at the explicit request of the user (i.e. when specifying either time_now or a value to the XML attribute seed).
  2. The dispersion feature of FGXMLElement which is now using a local instance of JSBSim::RandomNumberGenerator which seed is based on the system clock. The purpose of the code is that the dispersion will change at each execution of a script (currently the dispersion is identical at each execution which kind of defeats the purpose of testing how some parameters dispersion influences the script results).

@bcoconni bcoconni merged commit e27d0ae into JSBSim-Team:master Sep 10, 2022
@bcoconni bcoconni deleted the remove-static-members branch September 10, 2022 12:43
bcoconni added a commit to bcoconni/jsbsim that referenced this pull request Sep 24, 2022
…ibrary to generate random numbers. (JSBSim-Team#715)

This addresses the issue JSBSim-Team#666.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant