function indexList = binpack(songList, mediaLength)
% Arrange elements of the song list so that total play time
% is as close as possible to the target time. In general,
% not every song will be used.
% Reduces computation to speed up Entry 02.d a bit.
%Performance would be time-dependent.
total_songs = length(songList);
tmp01 = rand(15,total_songs);
[tmp02,order] = sort(tmp01(i,:));
cums = cumsum(songList(order));
upto = max(find(cums <= mediaLength));
total_length = cums(upto);
tmpList = order(1:upto);
if ((i==1)|(best_length < total_length))
indexList = tmpList;
best_length = total_length;