I want to randomly sort my dictionary, here is my code
what should I do ?
MY CODE:
Dim key2 As Variant, ArrayDict As Variant
'create array from dict
k = 1
For Each key2 In dict
ArrayDict(k, 1) = key2
ArrayDict(k, 2) = dict(key2)
k = k + 1
Next key2
' empty the dict
dict.RemoveAll
'randomize array order
For i = 1 To k' mix candidate cities
a1 = random(1, k)
a2 = random(1, k)
a = ArrayDict(a1, 1): ArrayDict(a1, 1) = ArrayDict(a2, 1) : ArrayDict(a2, 1) = a
a = ArrayDict(a1, 2) : ArrayDict(a1, 2) = ArrayDict(a2, 2) : ArrayDict(a2, 2) = a
Next i
'we filled the dict from the array
For i = 1 TB UBound(ArrayDict)
dict(ArrayDict(k, 1)) = ArrayDict(k, 2)
Next i
Thanks in advance
what should I do ?
MY CODE:
Dim key2 As Variant, ArrayDict As Variant
'create array from dict
k = 1
For Each key2 In dict
ArrayDict(k, 1) = key2
ArrayDict(k, 2) = dict(key2)
k = k + 1
Next key2
' empty the dict
dict.RemoveAll
'randomize array order
For i = 1 To k' mix candidate cities
a1 = random(1, k)
a2 = random(1, k)
a = ArrayDict(a1, 1): ArrayDict(a1, 1) = ArrayDict(a2, 1) : ArrayDict(a2, 1) = a
a = ArrayDict(a1, 2) : ArrayDict(a1, 2) = ArrayDict(a2, 2) : ArrayDict(a2, 2) = a
Next i
'we filled the dict from the array
For i = 1 TB UBound(ArrayDict)
dict(ArrayDict(k, 1)) = ArrayDict(k, 2)
Next i
Thanks in advance