Shuffle

From Xojo Documentation

Revision as of 18:53, 19 November 2009 by WikiSysop (talk) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!


Description

Shuffles (rearranges randomly) the elements of an array.


Syntax

array.Shuffle

Part Type Description
array Any valid data type The array whose elements will be shuffled.


Notes

Shuffle works on arrays of any data type and any number of dimensions. It is based on a random number. An element of the original array has a roughly equal chance of appearing in any cell of the array after the shuffle, regardless of the size and number of dimensions of the array.


Examples

The following example shuffles a one-dimensional array and shows the result in a ListBox.

Dim aTest() as Integer
aTest=Array(0,1,2,3,4,5,6,7,8,9)
aTest.Shuffle
For i = 0 to Ubound(aTest)
 ListBox1.Addrow Str(aTest(i))
Next

The following example shuffles a two-dimensional array.

Dim myArray(5,5) as String
Dim i, j as Integer
For i=0 to 5
For j=0 to 5
  myArray(i,j)=Str(i)+Str(j)
 Next
Next
myArray.Shuffle


See Also

Dim statement; Array, Join, Split, Ubound functions; Append, IndexOf, Insert, Redim, Remove, Pop, Sort methods; ParamArray keyword.