Hi guys
I am trying to randomize the entries in a photo playlist array. It seems to work fine except for some reason the last 3-4 entries do not randomize to the new array - they’re chopped off.
I am looping through the playlist array, and after I randomly find and copy an entry to a new array, I delete the array entry so it won’t be used again.
According to the documentation, the RND function should randomize between 0 and 1. So if I perform RND(1), shouldn’t the result be 0 or 1? Or, RND(3) result be 0,1,2, or 3?
Here is a sample of my print output:
ext1:/Photos/1.jpg
ext1:/Photos/2.jpg
ext1:/Photos/3.jpg
ext1:/Photos/4.jpg
ext1:/Photos/5.jpg
ext1:/Photos/6.jpg
ext1:/Photos/7.jpg
ext1:/Photos/8.jpg
ext1:/Photos/9.jpg
ext1:/Photos/10.jpg
Length of playlist = 10
(Length of playlist : random array position > new array position)
10 : 7 > 0
9 : 2 > 1
8 : 6 > 2
7 : 1 > 3
6 : 5 > 4
5 : 2 > 5
Sample code:
index = 0
for each item in playlist_master
’ Calculate the new length of the master playlist
playlist_master_count = playlist_master.count()
if playlist_master_count > 0
’ Get a random index value
random_index = RND(playlist_master_count)
’ Get playlist item from master playlist based on random index value
playlist_item = playlist_master[random_index]
’ Copy the playlist item to the new randomized playlist
playlist_random.Push(playlist_item)
’ Remove the copied playlist item from master so it isn’t copied again
playlist_master.Delete(random_index)
else
‘Just copy last entry’
playlist_item = playlist_master[playlist_master_count]
playlist_random.Push(playlist_item)
playlist_master.Delete(playlist_master_count)
end if
’ Log playlist processing
print playlist_master_count;" :“;random_index;” >";index
index = index + 1
end for
Thanks for any suggestions
AC
