Bugzilla – Bug 1964
Last modified: 2014-09-12 16:06:14 EDT
Ruben Martinez reported the below to me; I'm opening a bug so I don't forget it. Below text is from Ruben:
I'm using a UniformRandomVariable::GetInteger to generate LTP Session Ids, like this:
* Session numbers chosen by LTP senders shall be in the range [1, 2^32-1]
static const uint32_t MIN_SESSION_NUMBER = 1;
static const uint32_t MAX_SESSION_NUMBER = 4294967295U;
I noticed that when called with those parameters GetInteger always returns a 0.
After checking the source code for RandomVariable, I found that the max parameter is increased by 1 (and thus it becomes 2^32 = 0 ).
183 UniformRandomVariable::GetInteger (uint32_t min, uint32_t max)
185 NS_LOG_FUNCTION (this << min << max);
186 NS_ASSERT (min <= max);
187 return static_cast<uint32_t> ( GetValue (min, max + 1) );
I had to substract 1 to MAX_SESSION_NUMBER in the call to GetInteger to get a return value within the range.
Doesn't look like this behaviour was intended.
Call is to
double GetValue (double, double);
So force the arguments to double before the addition:
return static_cast<uint32_t> ( GetValue (min, max + 1.0) );
return static_cast<uint32_t> ( GetValue ((double)(min), (double)(max) + 1.0) );
fixed in 10935:8c52d989750b