Quick 'n' Dirty Array Reordering

The following code lists the contents of an array in a hard-coded order. Next, the array is randomly reordered and displayed. (Refresh the page to see the values change!)


The Hard-Coded Array Display
4GuysFromRolla.com
ASPMessageboard.com
ASPFAQs.com

The Randomly Reordered Array Display
ASPMessageboard.com
ASPFAQs.com
4GuysFromRolla.com

ReOrdering Code
Function JumbleArray(ByVal aArray)

  Dim iUpper, iLower, iLoop, iSwapPos, varTmp
  iUpper = UBound(aArray)
  iLower = LBound(aArray)

  Randomize Timer
  For iLoop = iLower to iUpper
    iSwapPos = Int(Rnd * (iUpper + 1))

    varTmp = aArray(iLoop)
    aArray(iLoop) = aArray(iSwapPos)
    aArray(iSwapPos) = varTmp

  Next

  JumbleArray = aArray
End Function


[Return to the Article] | [View the Single-Dimension Ordering Demo] | [View the Recordset Reordering Demo]