random_index = RND(playlist_master_count) - 1
"TheEndless" wrote:
Rnd(3) will produce values of 1, 2, or 3. Never 0, so you should pull your random index with:random_index = RND(playlist_master_count) - 1
function Shuffle(array as Object) as Void
for i% = array.count()-1 to 1 step -1
j% = Rnd(i% + 1) - 1
t = array[i%] : array[i%] = array[j%] : array[j%] = t
end for
end function
"RokuMarkn" wrote:
foreach won't work correctly if you delete entries in the array while traversing it. You may want to look at the Fisher-Yates shuffling algorithm, which is a simple way to shuffle an array in-place.
function Shuffle(array as Object) as Void
for i% = array.count()-1 to 1 step -1
j% = Rnd(i% + 1) - 1
t = array[i%] : array[i%] = array[j%] : array[j%] = t
end for
end function
--Mark