Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Sub nw()

Dim I as integer

Dim x, z

Range("B1").Select

For i=1 to 10

ActiveCell.Offset(columnOffset:=1).Activate

Z=StdNormNum()

ActiveCell.FormulaR1C1 = z

ActiveCell.Offset(columnOffset:=1).Activate

X=0.3+.6*z

ActiveCell.FormulaR1C1 = x

ActiveCell.Offset(columnOffset:=1).Activate

ActiveCell.FormulaR1C1 = 40*exp(x)

ActiveCell.Offset(rowOffset:=1).Activate

Next i

End Sub

Function StdNormNum() As Double

Dim v1 As Double, v2 As Double, w As Double, fac As


Double Dim snnUse As Double

Static flagSave As Integer: If IsEmpty(flagSave) Then


flagSave = 0 Static snnSave As Double

If (flagSave = 0) Then NewTrial:

v1 = 2# * Rnd 1#

v2 = 2# * Rnd 1# w = v1 ^ 2 + v2 ^ 2

If (w >= 1#) Then GoTo NewTrial fac = Sqr(2# *


Log(w) / w) snnSave = fac * v1

snnUse = fac * v2 flagSave = 1

Else

snnUse = snnSave flagSave = 0

End If

StdNormNum = snnUse End Function

You might also like