Bug 660

Summary: NormalVariable RNG's first returned value is not expected
Product: ns-3 Reporter: Antti Mäkelä <antti.makela>
Component: coreAssignee: ns-bugs <ns-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: dnlove, mathieu.lacage, tomh
Priority: P5    
Version: pre-release   
Hardware: All   
OS: All   
Attachments: Program that shows oddities in NormalVariable.
fixed the first erroneous value of GetValue from NormalVariable
fixed the first erroneous value of GetValue from NormalVariable
fixed the first erroneous value of GetValue from NormalVariable and removed unused variable

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