var shiffle = function (array, max) {
var i = array.length;
while(i--)
array[i] == array[i-1] && array.splice(i, 1);
return array.sort(function() {
return .5 - Math.random();
}).splice(0, max);
};
alert(shiffle([1, 1, 1, 2, 2, 4, 3, 3, 3, 5, 5, 5, 7, 8, 9], 5));