Adding UniformVariable::GetInteger and using it to fix bug in RealRandomStream::GetNext.
authorTimo Bingmann <timo.bingmann@student.kit.edu>
Wed, 04 Mar 2009 18:55:32 +0100
changeset 4256 cc06d903ca09
parent 4255 07f1fdd8a33e
child 4257 3e8f8052e155
Adding UniformVariable::GetInteger and using it to fix bug in RealRandomStream::GetNext.
src/core/random-variable.cc
src/core/random-variable.h
src/devices/wifi/random-stream.cc
--- a/src/core/random-variable.cc	Wed Mar 04 11:34:51 2009 +0000
+++ b/src/core/random-variable.cc	Wed Mar 04 18:55:32 2009 +0100
@@ -274,6 +274,11 @@
   return ((UniformVariableImpl*)Peek())->GetValue(s,l);
 }
 
+uint32_t UniformVariable::GetInteger (uint32_t s, uint32_t l)
+{
+  NS_ASSERT(s <= l);
+  return static_cast<uint32_t>( GetValue(s, l+1) );
+}
 
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
--- a/src/core/random-variable.h	Wed Mar 04 11:34:51 2009 +0000
+++ b/src/core/random-variable.h	Wed Mar 04 18:55:32 2009 +0100
@@ -200,6 +200,13 @@
   */
   double GetValue(double s, double l);
 
+  /**
+   * \brief Returns a random unsigned integer from the interval [s,l] including both ends.
+   * \param s Low end of the range
+   * \param l High end of the range
+   * \return A random unsigned integer value.
+   */
+  uint32_t GetInteger (uint32_t s, uint32_t l);
 };
 
 /**
--- a/src/devices/wifi/random-stream.cc	Wed Mar 04 11:34:51 2009 +0000
+++ b/src/devices/wifi/random-stream.cc	Wed Mar 04 18:55:32 2009 +0100
@@ -34,7 +34,7 @@
 uint32_t 
 RealRandomStream::GetNext (uint32_t min, uint32_t max)
 {
-  return static_cast<uint32_t> (round (m_stream.GetValue (min, max)));
+  return m_stream.GetInteger (min, max);
 }