티스토리 뷰

'Normal dist. Random number Generator
Option Explicit

Sub B_M_G()

    Const pi = 3.14159265358979
    Dim i As Integer, N As Double
    Dim u1 As Double, u2 As Double, u3 As Double
    Dim a1 As Double
    Dim p1 As Double, p2 As Double
    Dim nr1 As Double, nr2 As Double, nr3 As Double
    Dim s As Worksheet
   
    Set s = Sheet1
    N = InputBox("얼마나 생성할까?", "생성하고 싶은 개수")
           
    For i = 0 To N
       
'Box-Muller Generator
    u1 = Rnd()
    u2 = Rnd()
    a1 = Sqr(-2 * Log(u1))
    p1 = Sin(2 * pi * u2)
    p2 = Cos(2 * pi * u2)
    nr1 = a1 * p1
    nr2 = a1 * p2
   
   
'12진수법 Generator
    u3 = Rnd() + Rnd() + Rnd() + Rnd() + Rnd() + Rnd() + Rnd() + Rnd() + Rnd() + Rnd() + Rnd() + Rnd()
    nr3 = u3 - 6
      
       
    Cells(2 + i, 1) = nr1
    Cells(2 + i, 2) = nr2
    Cells(2 + i, 3) = nr3
   
    Next i
   
   
   
   
End Sub