Володимир,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<button id="pasha">click</button>
<output id="out">
<script>
var num = 3;
var last;
var arr = [];
function randomNumbe() {
return Math.floor(Math.random() * num);
}
function pusk() {
if (arr.length === 0) {
rnd: for (var a = 0; a < num; a++) {
var randoM = randomNumbe();
if (last === randoM) {
a--;
continue rnd;
}
for (var i = 0; i < arr.length; i++) {
if (arr[i] === randoM) {
a--;
continue rnd;
}
}
arr.push(randoM);
last = void 0;
}
}
last = arr.shift();
document.getElementById("out").innerHTML += " " + last;
}
document.getElementById("pasha").addEventListener("click", pusk);
</script>
</body>
</html>