var genArray = (function() {
var length = 5,
range = [-100, 100];
function getRandomInt() {
return Math.floor(Math.random() * (range[1] - range[0] + 1)) + range[0];
}
return function() {
var n, result = [];
while(result.length < length) {
n = getRandomInt();
if(result.indexOf(n) === -1) {
result.push(n);
}
}
return result;
}
})();
<button onclick="alert(genArray())">CLICK</button>