nam2000ind

i made this programme in console application this is my code and i want to the result of 100000 number..
but after crossing 10000 value i m getting infinativ values....
but in other language like java ...i run the same programme .....it is running perfactly can u guide me where i m doing mistake...rnd() is the random value.....here is the result which i want

0.9997669278359024
1.9879226451633236
0.9931218457149422



Module question1
Sub main()
Dim c AsInteger
Dim RNDNO AsSingle
Dim j, S, T, SX, R, I, SR, SI, X AsDouble

c = 0
SX = 0
SR = 0
SI = 0
For j = 1 To 100000
S = 0
T = 100 - 500 * Math.Log(1 - Rnd())

RNDNO = Math.Log(Rnd())
130: X = -Math.Log(rnd())
c = c + 1
SX = SX + X
S = S + X
If (S < T) ThenGoTo 130
R = S - T
I = X
SR = SR + R
SI = SI + I


Next j
Console.WriteLine(SX / c)
Console.WriteLine(SI / 100000)
Console.WriteLine(SR / 100000)
EndSub
End
Module



Re: Visual Basic Language getting infinite value...after 10000 value

Spidermans_DarkSide

Hi,

Posting twice is not necessary.

See same at.>> http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1178758&SiteID=1

Regards,

S_DS






Re: Visual Basic Language getting infinite value...after 10000 value

MS Johan Stenberg

Hint: What is the range of possible return values for Rnd() And what happens if you give Math.Log the minimum and/or maximum return value of Rnd()

Best regards,
Johan Stenberg






Re: Visual Basic Language getting infinite value...after 10000 value

spotty

I think I would probably be looking at the types as well - your using integer and single data types.