function indexList = binpack(songList, mediaLength)
mediaLength = mediaLength-0.00001;
total_songs = length(songList);
num_random_trials = 100;
rand('seed',sum(100*clock));
[tmp1,order] = sort(rand(num_random_trials,total_songs),2);
gap = mediaLength*ones(num_random_trials,1);
selected=logical(zeros(num_random_trials,total_songs));
for s=1:total_songs
addIndex=find(gap>=songList(order(:,s))');
if ~isempty(addIndex)
gap(addIndex)=gap(addIndex)'-songList(order(addIndex,s));
selected(addIndex,s)=ones(length(addIndex),1);
end;
end;
[tmp2,bestTrial]=min(gap);
indexList=order(bestTrial,selected(bestTrial,:));
|