 How to create 5 random numbers but in each step, exclude the previous results?

Hi, I am trying to write a program that will generate 5 random numbers, but in each step, I would like to exclude the previous value from the next possible values. In short, if I generate 5 random numbers, I do not want to have any duplicates. Then I am trying to have the computer guess 5 numbers, and see how many times it took to actually hit all 5 of them correctly.

I wrote a program without the above restriction, but I cannot get how I can limit the results to exclude the previously guessed or generated values (unless in each step I put an if statement, witch will have additional restrictions in each step). Maybe an approach with a list would be more suitable?

var upper = 40;

var randomNumberA = getRandomNumber(upper); var randomNumberB = getRandomNumber(upper); var randomNumberC = getRandomNumber(upper); var randomNumberD = getRandomNumber(upper); var randomNumberE = getRandomNumber(upper);

var guessA; var guessB; var guessC; var guessD; var guessE;

var attempts = 0;

function getRandomNumber (upper) { return Math.floor (Math.random() * upper) +1; }

while (randomNumberA !== guessA || randomNumberB !== guessB || randomNumberC !== guessC || randomNumberD !== guessD || randomNumberE !== guessE ) {

guessA = getRandomNumber(upper); guessB = getRandomNumber(upper); guessC = getRandomNumber(upper); guessD = getRandomNumber(upper); guessE = getRandomNumber(upper);

attempts += 1; }

document.write("<p>The random numbers were: " + randomNumberA + " " + randomNumberB + " "+ randomNumberC + " " + randomNumberD + " " + randomNumberE + " " + "<p>");

document.write("It took the computer " + attempts + " attempts to get it rights.</p>"); 