Use C++11 standard library to generate random numbers #715
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses issue #666 and allows removing the static method
FGJSBBase::GaussianRandomNumber
and its static membergaussian_random_number_phase
.The method
FGJSBBase::GaussianRandomNumber
is replaced by the C++ standard library classstd::normal_distribution
and all the other calls to the system functionrand()
have been replaced by the C++ standard library classstd::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 ofRandomNumberGenerator
so that callingFGFDMExec::Srand()
(or setting the propertysimulation/randomseed
) has a global effect over JSBSim random number generation.There are 2 exceptions to this behavior:
FGFunction::makeRandomEngine
which allows using specific instances ofJSBSim::RandomNumberGenerator
at the explicit request of the user (i.e. when specifying eithertime_now
or a value to the XML attributeseed
).FGXMLElement
which is now using a local instance ofJSBSim::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).