1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
6 #include <cpPluginsBase/RandomNumberSource.h>
8 // -------------------------------------------------------------------------
9 cpPluginsBase::RandomNumberSource::
15 // -------------------------------------------------------------------------
16 cpPluginsBase::RandomNumberSource::
17 ~RandomNumberSource( )
21 // -------------------------------------------------------------------------
22 void cpPluginsBase::RandomNumberSource::
25 this->ConfigureOutValue< TReal >( "Number" );
28 // -------------------------------------------------------------------------
29 void cpPluginsBase::RandomNumberSource::
32 // Seed with a real random value, if available
35 // Choose a random mean between 1 and 6
36 std::default_random_engine e1( r( ) );
37 std::uniform_int_distribution< int > uniform_dist( 1, 6 );
38 int mean = uniform_dist( e1 );
40 // Generate a normal distribution around that mean
41 std::seed_seq seed2{ r( ), r( ), r( ), r( ), r( ), r( ), r( ), r( ) };
42 std::mt19937 e2( seed2 );
43 std::normal_distribution<> normal_dist( mean, 2 );
45 // Configure a random number as output
46 this->SetOutValue( "Number", normal_dist( e2 ) );