Q:

Writing wrong values to log files after concurrent calls of a script

This code sample is part of a vbscript script that
is making HTTP POST requests for sending SMS through an API. For each SMS, I need a unique random ID. A description of the functions:
WriteLog (Create log files)
MoveLogFiles (Archiving old log files)
CreateGUID (Generate GUIDs for each SMS)
The problem here is when I write to the log file. I tried apache benchmark to stress test my script. In the log file, the smsID is not stored correctly. It is supposed to be unique for each http request. Instead I see the same ID written in many entries in the log file. How can I protect the variable so that it writes the appropriate value in the log file when the script is called multiple times?  
Private smsID
smsID = CreateGUID(12)
'HTTP Request & Response 
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
WriteLog smsID, "[SMS ID:" & smsID & "] Starting HTTP Request..." 
WriteLog smsID, "[SMS ID:" & smsID & "] JSON to be sent: " & JSONStringNoPIN
WriteLog smsID, "[SMS ID:" & smsID & "] Sending HTTP Request..."
ASPPostJSON(smsID)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
set JSONString = Nothing
set JSONStringNoPIN = Nothing
set JSONRequest = Nothing
logFilesDic.RemoveAll
Set logFilesDic = Nothing
WriteLog smsID, "[SMS ID:" & smsID & "] Finished..." & vbCrLf
Set smsID=Nothing

Function WriteLog(ByVal smsID_, ByVal psMessage)
    Dim fs: Set fs = Server.CreateObject("Scripting.FileSystemObject")

    ' Check if the log file and folder exists
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    dim f, logSize, logDic 
    On Error Resume Next
    Set f = fs.GetFile(logFile)
    Set logDic = CreateObject("Scripting.Dictionary")
    'logDic.Add "1", Now() & vbTab & "[SMS ID:" & smsID_ & "] Opening Log file: " & logFile   

    If Err.Number <> 0 Then
        logDic.Add "1", Now() &  vbTab & "[SMS ID:" & smsID_ & "] An error occured while opening the log file. Error #" & Err.Number & ": " & Err.Description       
        If Err.Number = 53 And Not fs.FileExists(logFile) Then 
            if Not fs.FolderExists Then
                fs.CreateFolder logDirectory
            End if
            if Not fs.FileExists(logFile) Then
                fs.CreateTextFile logFile
                logDic.Add "2", Now() &  vbTab & "[SMS ID:" & smsID_ & "] Log file was created: " & logFile
            End if
            Set f = fs.GetFile(logFile)
        End if  
    End if 
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    ' Check if the log size exceeds the log size limit 
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    logSize = f.Size
    if logSize >= logMaxSize Then
        logDic.Add "3", Now() &  vbTab & "[SMS ID:" & smsID_ & "] Log file is exceeding the maximum file size allowed:" & logMaxSize  & " Bytes. Archiving the current log file: " & logFile
        MoveLogFiles()
        fs.CreateTextFile logFile
        logDic.Add "4", Now() & vbTab & "[SMS ID:" & smsID_ & "] Log file was archived: " & logTemp
    End if
    set f=nothing
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    ' Write to the log file
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Application.Lock
        dim log, logDicItems
        Set log = fs.OpenTextFile(logFile, 8, True) '1=ForReading, 2=ForWriting, 8=ForAppending   

        If logDic.Exists("1") Then log.WriteLine logDic.Item("1")
        If logDic.Exists("2") Then log.WriteLine logDic.Item("2") 
        If logDic.Exists("3") Then log.WriteLine logDic.Item("3") 
        If logDic.Exists("4") Then log.WriteLine logDic.Item("4") 

        log.WriteLine Now() & vbTab & psMessage 
        log.Close 
    Application.UnLock
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Set log = Nothing
    fs.Close() 
    Set fs = Nothing 
    logDic.RemoveAll
    Set logDic = Nothing
    WriteLog = True 
End Function 

Function MoveLogFiles() 
    Dim fs: Set fs = Server.CreateObject("Scripting.FileSystemObject")
    For i = logMaxArchives To 1  Step -1
        if fs.FileExists(logFile & "." & CStr(i)) Then
            if i = logMaxArchives Then 
                fs.DeleteFile logDirectory & logFilesDic.Item(logMaxArchives)
            Else
                fs.MoveFile logDirectory & logFilesDic.Item(i), logDirectory & logFilesDic.Item(i+1)
            End if
        End if
    Next
    fs.MoveFile logDirectory & logFilesDic.Item(0), logDirectory & logFilesDic.Item(1)
    fs.Close()
End Function 

' Generate unique identifier for SMS
Function CreateGUID(tmpLength)
    Application.Lock
        if tmpLength >= 64 or tmpLength < 0 Then 
            WriteLog "Error when generating SMS ID. Maximum length of characters allowed: 64. Value given: " & tmpLength
        Elseif tmpLength < 4 Then
            WriteLog "Error when generating SMS ID. Minimum length of characters allowed: 4. Value given: " & tmpLength
        Else
            Randomize Timer
            Dim tmpCounter,tmpGUID
            Const strValid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            For tmpCounter = 1 To tmpLength
                tmpGUID = tmpGUID & Mid(strValid, Int(Rnd(1) * Len(strValid)) + 1, 1)
            Next
            CreateGUID = tmpGUID
        End if
    Application.UnLock
End Function

A:

Eventually the problem was caused by the Randomize Timer. Instead I used this:
Function CreateGUID()
    Dim TypeLib: Set TypeLib = CreateObject("Scriptlet.TypeLib")
    CreateGUID = TypeLib.Guid
    CreateGUID = Left(CreateGUID, Len(CreateGUID)-3)
    CreateGUID = Mid(CreateGUID,2)
    Response.Write CreateGUID 
End Function

