Best way to make multiple Random.Range not equal the same?

Hi community! In my game, I am making a system to spawn random furniture at random spots in my home. To do this, I have several GameObject Arrays in my script, each array for 1 furniture. Then I have a Transform Array for spawnpoints. It chooses a random furniture gameobject from each array using Random.Range(0,furngroup1.length) then chooses a random spawnpoint from the array using Random.Range(0,spawnpoints.length). After that I instantiate the chosen furniture at each chosen spawnpoint position. It all works well, except for 1 issue.

The exact code for choosing each spawnpoint is this:

sp1 = Random.Range(0,spawnpoints.length);
sp2 = Random.Range(0,spawnpoints.length);
sp3 = Random.Range(0,spawnpoints.length);
sp4 = Random.Range(0,spawnpoints.length);
sp5 = Random.Range(0,spawnpoints.length);
sp6 = Random.Range(0,spawnpoints.length);

But there is a chance that sp1 will be 7, but so will sp3, or sp2 and sp5, etc etc etc.

I made a workaround for it where it randomizes the numbers if sp1 == sp2, sp2 == sp3, etc and it works, however the numbers will change 3 or 4 times before finally being all different. Is there any way to generate the numbers without choosing one of the same value of another one?

This has been asked and answered many times on here.

Try searching this site for “random numbers not repeating” or something like that and you should find plenty of detailed answers.

In summary though, there are 2 ways that are often recommended. Both start with putting the numbers (or whatever) into a list.

In one method you pick a random element from the list and then remove it, and repeat for the next one, and so on.

The other way is to shuffle the list (ie sort it randomly) and then go through them in sequence.

Depending on exactly what you’re trying to achieve, one of those methods may be more suitable than the other. Or not.