Public Class Form1
Dim i As Long = 0
Dim Lambda As Double
Dim F As Double = 0
Dim p As Double = 0
Dim g As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim uRandom As Double
Randomize()
uRandom = Rnd()
Try
Lambda = Double.Parse(TextBox1.Text)
g = CType(Lambda, Int32)
Catch ex As Exception
MsgBox("Please Enter Mean(Lambda)", MsgBoxStyle.OkCancel,
"Warning")
End Try
p = (1 / Math.Exp(Lambda))
F = p
Level3:
If uRandom < F Then
Label2.Text = i
Exit Sub
Else
i = i + 1
p = (Lambda * p) / (g + 1)
F = F + p
GoTo Level3
End If