You will need to randomly generate numbers and check that they have not already been displayed. The below does this by continuosly looping until it has found the total range of values. Each loop generates a new number then checks if it exists in the array. If not the new value is appended and output to the screen.
var arrayContains = function(array, value) {
for(var i in array) {
if(array[i] == value) { return true; }
}
return false;
};
var found = [];
var range = 4; // 0 - 4
while(found.length < range) {
var num = Math.floor(Math.random() * (range + 1));
// If it is new then add it and print it
if(!arrayContains(found, num)) {
found[found.length] = num;
document.writeln(num);
}
}