Bug 660 - NormalVariable RNG's first returned value is not expected
NormalVariable RNG's first returned value is not expected
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: core
pre-release
All All
: P5 normal
Assigned To: ns-bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-08-12 08:29 UTC by Antti Mäkelä
Modified: 2009-08-24 21:33 UTC (History)
3 users (show)

See Also:


Attachments
Program that shows oddities in NormalVariable. (400 bytes, text/plain)
2009-08-12 08:29 UTC, Antti Mäkelä
Details
fixed the first erroneous value of GetValue from NormalVariable (462 bytes, patch)
2009-08-18 23:00 UTC, duy
Details | Diff
fixed the first erroneous value of GetValue from NormalVariable (462 bytes, patch)
2009-08-18 23:06 UTC, duy
Details | Diff
fixed the first erroneous value of GetValue from NormalVariable and removed unused variable (1.24 KB, patch)
2009-08-19 15:35 UTC, duy
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Antti Mäkelä 2009-08-12 08:29:12 UTC
Created attachment 552 [details]
Program that shows oddities in NormalVariable.

When using NormalVariable, the first GetValue() call after initialization returns a rather odd value.

Test program attached. Anyway, asking for 10 random values returns

1.06956e-311
13.8052
11.2844
9.71656
2.41641
8.41882
13.7028
7.21069
10.5926
11.8275
Comment 1 duy 2009-08-18 20:55:14 UTC
In "src/core/random-variable.cc", the variable m_nextValid  behaves a bit strange, I have no idea where it gets initialized to 248 after already being initialized to 0.
Output of the order of event in my log printout from random-variable.cc:

In constructor NormalVariableImpl m_nextValid 0
In NormalVariableImpl::GetValue() m_nextValid is 248

gdb debuging still shows the mysterious number 248 after it already gets assigned 0.  There isn't many places where m_nextValid gets assigned, and it's a mystery why it gets that value.



(In reply to comment #0)
> Created an attachment (id=552) [details]
> Program that shows oddities in NormalVariable.
> 
> When using NormalVariable, the first GetValue() call after initialization
> returns a rather odd value.
> 
> Test program attached. Anyway, asking for 10 random values returns
> 
> 1.06956e-311
> 13.8052
> 11.2844
> 9.71656
> 2.41641
> 8.41882
> 13.7028
> 7.21069
> 10.5926
> 11.8275
> 

Comment 2 duy 2009-08-18 23:00:51 UTC
Created attachment 563 [details]
fixed the first erroneous value of GetValue from NormalVariable

Apparently, we also must initialize variable m_nextValid in NormalVariableImpl::NormalVariableImpl(const NormalVariableImpl& c) as well.

Please see the patch.  I reran your example script it outputs fine now.

13.8052
11.2844
9.71656
2.41641
8.41882
13.7028
7.21069
10.5926
11.8275
10.5249
14.0481
Comment 3 duy 2009-08-18 23:06:59 UTC
Created attachment 564 [details]
fixed the first erroneous value of GetValue from NormalVariable

same patch, just rearrange it a bit to look nice.
Comment 4 Antti Mäkelä 2009-08-19 03:54:12 UTC
Seems to work now.
Comment 5 Mathieu Lacage 2009-08-19 04:40:50 UTC
if --regression still passes, please commit

I see that m_static_nextValid and m_static_next are unused: can you kill them in a separate patch if I am right and --regression still passes ?

Comment 6 duy 2009-08-19 15:35:31 UTC
Created attachment 565 [details]
fixed the first erroneous value of GetValue from NormalVariable and removed unused variable

fixed the erroneous first return of NormalVariable and removed unused variable "static bool   m_static_nextValid;"
"static double m_static_next;"
Comment 7 duy 2009-08-20 03:42:51 UTC
it passes regression tests, but I don't know how to commit, do you mean change the resolution to "fixed" and click "commit" and it will be applied in ns-3-dev?

(In reply to comment #5)
> if --regression still passes, please commit
> 
> I see that m_static_nextValid and m_static_next are unused: can you kill them
> in a separate patch if I am right and --regression still passes ?
> 

Comment 8 Tom Henderson 2009-08-21 15:24:17 UTC
(In reply to comment #7)
> it passes regression tests, but I don't know how to commit, do you mean change
> the resolution to "fixed" and click "commit" and it will be applied in
> ns-3-dev?

No, bugzilla is not linked to the repository in that way.  I'll contact you about this.

Comment 9 duy 2009-08-24 21:33:36 UTC
pushed in changeset 4736   fef6ccee5897