From 7f8370b67ee9622e7722c316df2a2d5d960f66d0 Mon Sep 17 00:00:00 2001 From: Timo Bingmann Date: Wed, 4 Mar 2009 18:55:32 +0100 Subject: [PATCH] Adding UniformVariable::GetInteger and using it to fix bug in RealRandomStream::GetNext. --- src/core/random-variable.cc | 5 +++++ src/core/random-variable.h | 7 +++++++ src/devices/wifi/random-stream.cc | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/random-variable.cc b/src/core/random-variable.cc index 402068679..70be8a201 100644 --- a/src/core/random-variable.cc +++ b/src/core/random-variable.cc @@ -274,6 +274,11 @@ double UniformVariable::GetValue(double s, double l) return ((UniformVariableImpl*)Peek())->GetValue(s,l); } +uint32_t UniformVariable::GetInteger (uint32_t s, uint32_t l) +{ + NS_ASSERT(s <= l); + return static_cast( GetValue(s, l+1) ); +} //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- diff --git a/src/core/random-variable.h b/src/core/random-variable.h index 50bb3c463..fc48ddf7a 100644 --- a/src/core/random-variable.h +++ b/src/core/random-variable.h @@ -200,6 +200,13 @@ public: */ 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); }; /** diff --git a/src/devices/wifi/random-stream.cc b/src/devices/wifi/random-stream.cc index 0b086442f..3542454cd 100644 --- a/src/devices/wifi/random-stream.cc +++ b/src/devices/wifi/random-stream.cc @@ -34,7 +34,7 @@ RealRandomStream::RealRandomStream () uint32_t RealRandomStream::GetNext (uint32_t min, uint32_t max) { - return static_cast (round (m_stream.GetValue (min, max))); + return m_stream.GetInteger (min, max); }