Get an Array Populated With Distinct Random Values

Search

 by Remas Wojciechowski

This function returns for an array populated with [intCount] number of distinct integer values from the range [intL] to [intU].

Function ARRAY_GetRandomSet_Distinct(ByVal intL, ByVal intU, ByVal intCount)
   Dim aRandomSet()
   Dim i
   Dim intRandom
   ReDim aRandomSet(0)
   For i = 0 To intCount - 1
      intRandom = GetRandomInRange(intL, intU)
      Do Until GetIndex_InArray(aRandomSet, intRandom, 0) = -1
         intRandom = GetRandomInRange(intL, intU)
      Loop
      aRandomSet(i) = intRandom
      If i < intCount - 1 Then ReDim Preserve aRandomSet(i + 1)
   Next
   ARRAY_GetRandomSet_Distinct = aRandomSet
End Function