SubName: Shuffle a string array.
Description: Use this code to randomly shuffle a string array.
Example:
"1, 2, 3, 4, 5, 6, 7, 8, 9" will be shuffled to become a random string array, something like "6, 5, 4, 2, 8, 9, 7, 1, 3".
Tags: Shuffle, Random, String, Array
Description: Use this code to randomly shuffle a string array.
Example:
"1, 2, 3, 4, 5, 6, 7, 8, 9" will be shuffled to become a random string array, something like "6, 5, 4, 2, 8, 9, 7, 1, 3".
B4X:
Dim CardArray() As String = Array As String(1, 2, 3, 4, 5, 6, 7, 8, 9)
ShuffleArray(CardArray)
'Generate random string array
Public Sub ShuffleArray(StringArray() As String)
Dim ArrayVal As String
Dim Random As Int
For i = 0 To StringArray.Length - 1
Random = Rnd(i, StringArray.Length)
ArrayVal = StringArray(i)
StringArray(i) = StringArray(Random)
StringArray(Random) = ArrayVal
Next
End Sub
Tags: Shuffle, Random, String, Array
Last edited: