Generating Random Variables in VBA

Uniform distributiom Rnd()

Public Function UniformRand() As Double

UniformRand = Rnd()

End Function

或者 a到b之间随机整数

Public Function Uniform( a As Double, b As Double ) As Double

Uniform = Int( a + Rnd() * (b - a + 1) )

End Function

Normal Distribution

Function Random_SNorm1() As Double

Dim u1 As Double

Dim u2 As Double

u1 = Rnd()

u2 = Rnd()

Random_SNorm1 = Sqr(-2 * Log(u1)) * Cos(2 * 3.1415927 * u2)

End Function

你可能感兴趣的:(Generating Random Variables in VBA)