Adding UniformVariable::GetInteger and using it to fix bug in RealRandomStream::GetNext.

This commit is contained in:
Timo Bingmann
2009-03-04 18:55:32 +01:00
parent a4c4aec51c
commit 7f8370b67e
3 changed files with 13 additions and 1 deletions

View File

@@ -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<uint32_t>( GetValue(s, l+1) );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

View File

@@ -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);
};
/**

View File

@@ -34,7 +34,7 @@ RealRandomStream::RealRandomStream ()
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);
}