Revision: 7713
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7713&view=rev
Author:   natepak
Date:     2009-05-23 16:29:36 +0000 (Sat, 23 May 2009)

Log Message:
-----------
Added a random number class

Modified Paths:
--------------
    code/gazebo/trunk/server/CMakeLists.txt

Added Paths:
-----------
    code/gazebo/trunk/server/Rand.cc
    code/gazebo/trunk/server/Rand.hh

Modified: code/gazebo/trunk/server/CMakeLists.txt
===================================================================
--- code/gazebo/trunk/server/CMakeLists.txt     2009-05-23 00:33:08 UTC (rev 
7712)
+++ code/gazebo/trunk/server/CMakeLists.txt     2009-05-23 16:29:36 UTC (rev 
7713)
@@ -63,6 +63,7 @@
              GraphicsIfaceHandler.cc
              GuiAPI.cc
              Simulator.cc
+             Rand.cc
 )
 
 SET (headers Common.hh
@@ -87,6 +88,7 @@
              GraphicsIfaceHandler.hh
              GuiAPI.hh
              Simulator.hh
+             Rand.hh
 )
 
 APPEND_TO_SERVER_HEADERS(${headers})

Added: code/gazebo/trunk/server/Rand.cc
===================================================================
--- code/gazebo/trunk/server/Rand.cc                            (rev 0)
+++ code/gazebo/trunk/server/Rand.cc    2009-05-23 16:29:36 UTC (rev 7713)
@@ -0,0 +1,54 @@
+#include <ctime>
+#include "Rand.hh"
+
+using namespace gazebo;
+
+GeneratorType *Rand::randGenerator = new GeneratorType(std::time(0));
+
+///////////////////////////////////////////////////////////////////////////////
+// Constructor
+Rand::Rand()
+{
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Destructor
+Rand::~Rand()
+{
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// Get a double from a uniform distribution
+double Rand::GetDblUniform(double min, double max)
+{
+  URealGen gen(*randGenerator, UniformRealDist(min, max));
+ 
+  return gen(); 
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// Get a double from a normal distribution
+double Rand::GetDblNormal(double mean, double sigma)
+{
+  NRealGen gen(*randGenerator, NormalRealDist(mean, sigma));
+ 
+  return gen(); 
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// Get a integer from a uniform distribution
+int Rand::GetIntUniform(int min, int max)
+{
+  UIntGen gen(*randGenerator, UniformIntDist(min,max));
+ 
+  return gen(); 
+}
+
+///////////////////////////////////////////////////////////////////////////////
+/// Get a double from a normal distribution
+int Rand::GetIntNormal(int mean, int sigma)
+{
+  NRealGen gen(*randGenerator, NormalRealDist(mean, sigma));
+ 
+  return (int)(gen()); 
+}

Added: code/gazebo/trunk/server/Rand.hh
===================================================================
--- code/gazebo/trunk/server/Rand.hh                            (rev 0)
+++ code/gazebo/trunk/server/Rand.hh    2009-05-23 16:29:36 UTC (rev 7713)
@@ -0,0 +1,53 @@
+#ifndef RAND_HH
+#define RAND_HH
+
+#include <boost/random.hpp>
+
+namespace gazebo
+{
+
+  typedef boost::mt19937 GeneratorType;
+  typedef boost::uniform_real<double> UniformRealDist;
+  typedef boost::normal_distribution<double> NormalRealDist;
+  typedef boost::uniform_int<int> UniformIntDist;
+
+  typedef boost::variate_generator<GeneratorType&, UniformRealDist > URealGen;
+  typedef boost::variate_generator<GeneratorType&, NormalRealDist > NRealGen;
+  typedef boost::variate_generator<GeneratorType&, UniformIntDist > UIntGen;
+
+  /// \brief Random number generator class
+  class Rand
+  {
+    /// \brief Constructor
+    private: Rand();
+
+    /// \brief Destructor
+    private: virtual ~Rand();
+ 
+    /// \brief Get a double from a uniform distribution
+    /// \param min Minimum bound for the random number
+    /// \param max Maximum bound for the random number
+    public: static double GetDblUniform(double min=0, double max=1);
+
+    /// \brief Get a double from a normal distribution
+    /// \param mean Mean value for the distribution
+    /// \param sigma Sigma value for the distribution
+    public: static double GetDblNormal(double mean=0, double sigma=1);
+
+    /// \brief Get a integer from a uniform distribution
+    /// \param min Minimum bound for the random number
+    /// \param max Maximum bound for the random number
+    public: static int GetIntUniform(int min, int max);
+
+    /// \brief Get a double from a normal distribution
+    /// \param mean Mean value for the distribution
+    /// \param sigma Sigma value for the distribution
+    public: static int GetIntNormal(int mean, int sigma);
+  
+    // The random number generator
+    private: static GeneratorType *randGenerator;
+  };
+  
+}
+
+#endif


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, & 
iPhoneDevCamp asthey present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://www.creativitycat.com 
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to