Shuffling an Int Array

BlitzMax Forums/BlitzMax Beginners Area/Shuffling an Int Array

The Forum Archive is locked. These are the original blitzbasic.com forums, kept so their posts can still be read and searched. No new topics, replies or edits can be made here. To join the conversation, head over to the Blitz3D+ forums.

Ok one more modification. I added in the number of times you want to shuffle the numbers.

SeedRnd MilliSecs()

Local array:Int[] = ShuffleIntArray([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20])

For i = 0 To array.length-1
	Print array[i]
Next

End

Function ShuffleIntArray%[](array%[], numShuffles%=10)
	Local i%, j%, r%, temp%
	For j = 0 To numShuffles-1
		For i = 0 To array.length-1
			r = Rand(array.length)-1
			temp = array[i]
			array[i] = array[r]
			array[r] = temp 
		Next
	Next
	Return array
End Function