Sunday, August 01, 2010     | Register
TradersStudio Forums
Subject: RandomizeArray2()

You are not authorized to post a reply.   
Author Messages
trollaby
Posts:12

08-20-2009 1:45 PM Alert 

 I'm intrested to montecarlo simulation but this function is very hard to understand . Is there someone who can explain some piece of code : 

Sub RandomizeArray2(Piece)
    Dim A1 As Array
    Dim A2 As Array

    Dim i As Integer
    Dim r As Integer
    Dim j As Integer
    Dim k As Integer
    Dim flags As Array
    Dim b As Boolean
    Dim tmp As Double
    Dim n As Integer
    Dim nPieces As Integer
    Dim lo As Integer

    A1 = Gvalue1

    n = UBound(A1)
    nPieces = Floor(n/Piece)           Why this ? you suggest 20 in the example why 20

    ReDim (A2, n)
    ReDim (flags, nPieces)

   For i = 0 To nPieces - 1
        b = False                             What is b ?  why should be false
        
       r = lo + Rnd(nPieces - lo - 1)       What lo ? it supposes to be 0 always ?
        j = r

       What is the meaning of all of this

        If j > lo Then                         What's the meaning of this
            While (j >= 0)                     
                If Not flags[j] Then         and this
                    b = True                     why b should be true
                    Exit While
                End If                                  

                j = j - 1
            Wend
        End If

     
      
        If Not b Then                               what's the meaning "if not b"
            j = r
            If j < lo Then j = lo           
            While (j < nPieces)
                If Not flags[j] Then               again what the meaning of this
                    lo = j
                    b = True
                    Exit While
                End If

                j = j + 1
            Wend
        End If

        If Not b Then GoTo func_end          

' swap

        'Print i, " -> ", j

        For k = 0 To Piece - 1
            A2[j * Piece + k] = A1[i * Piece + k]
        Next

        Assert(Not flags[j])                                              Why this

        flags[j] = True
    Next

func_end:
    For i = nPieces * Piece To n - 1
        A2[i] = A1[i]
    Next

    gvalue1 = A2
End Sub

 There is some place where i can fine explanation of the codes, because it would be very useful.

Thank you

 

 

You are not authorized to post a reply.



ActiveForums 3.6
TradersStudio® Copyright 2004-2010 All Rights Reserved   |  Privacy Statement  |  Terms Of Use