]> Creatis software - cpPlugins.git/blob - lib/cpPluginsBase/RandomNumberSource.cxx
Moved to version 1.0
[cpPlugins.git] / lib / cpPluginsBase / RandomNumberSource.cxx
1 // =========================================================================
2 // @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4
5 #include <random>
6 #include <cpPluginsBase/RandomNumberSource.h>
7
8 // -------------------------------------------------------------------------
9 cpPluginsBase::RandomNumberSource::
10 RandomNumberSource( )
11   : Superclass( )
12 {
13 }
14
15 // -------------------------------------------------------------------------
16 cpPluginsBase::RandomNumberSource::
17 ~RandomNumberSource( )
18 {
19 }
20
21 // -------------------------------------------------------------------------
22 void cpPluginsBase::RandomNumberSource::
23  _Configure( )
24 {
25   this->ConfigureOutValue< TReal >( "Number" );
26 }
27
28 // -------------------------------------------------------------------------
29 void cpPluginsBase::RandomNumberSource::
30 _GenerateData( )
31 {
32   // Seed with a real random value, if available
33   std::random_device r;
34  
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 );
39  
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 );
44
45   // Configure a random number as output
46   this->SetOutValue( "Number", normal_dist( e2 ) );
47 }
48
49 // eof - $RCSfile$