]> Creatis software - cpPlugins.git/blobdiff - lib/cpPluginsBase/RandomNumberSource.cxx
Moved to version 1.0
[cpPlugins.git] / lib / cpPluginsBase / RandomNumberSource.cxx
diff --git a/lib/cpPluginsBase/RandomNumberSource.cxx b/lib/cpPluginsBase/RandomNumberSource.cxx
new file mode 100644 (file)
index 0000000..c49f748
--- /dev/null
@@ -0,0 +1,49 @@
+// =========================================================================
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// =========================================================================
+
+#include <random>
+#include <cpPluginsBase/RandomNumberSource.h>
+
+// -------------------------------------------------------------------------
+cpPluginsBase::RandomNumberSource::
+RandomNumberSource( )
+  : Superclass( )
+{
+}
+
+// -------------------------------------------------------------------------
+cpPluginsBase::RandomNumberSource::
+~RandomNumberSource( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsBase::RandomNumberSource::
+ _Configure( )
+{
+  this->ConfigureOutValue< TReal >( "Number" );
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsBase::RandomNumberSource::
+_GenerateData( )
+{
+  // Seed with a real random value, if available
+  std::random_device r;
+  // Choose a random mean between 1 and 6
+  std::default_random_engine e1( r( ) );
+  std::uniform_int_distribution< int > uniform_dist( 1, 6 );
+  int mean = uniform_dist( e1 );
+  // Generate a normal distribution around that mean
+  std::seed_seq seed2{ r( ), r( ), r( ), r( ), r( ), r( ), r( ), r( ) }; 
+  std::mt19937 e2( seed2 );
+  std::normal_distribution<> normal_dist( mean, 2 );
+
+  // Configure a random number as output
+  this->SetOutValue( "Number", normal_dist( e2 ) );
+}
+
+// eof - $RCSfile$