' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Function funcRandom(intLow As Integer, intHigh As Integer) As Integer
    funcRandom = Int((intHigh - intLow + 1) * Rnd) + intLow
End Function
Function GenPassword(nchar As Integer, nupcas As Integer)
    Const valid As String = "abcdefghijklmnopqrstuwvxyz"
    Dim res As String
    Dim i, n, ix As Integer
    Dim uc() As Boolean
    Randomize
    ReDim uc(nchar)
    n = nupcas
    While n > 0
        ix = funcRandom(1, nchar)
        If Not uc(ix) Then
            uc(ix) = True
            n = n - 1
        End If
    Wend
    res = ""
    For i = 1 To nchar
        If uc(i) Then
            res = res & UCase(Mid(valid, funcRandom(1, Len(valid)), 1))
        Else
            res = res & Mid(valid, funcRandom(1, Len(valid)), 1)
        End If
    Next
    GenPassword = res
End Function
Function testGenPassword()
    MsgBox GenPassword(6, 2)
End Function
