Answer the question
In order to leave comments, you need to log in
How to make a ramdom object spawn without repeating?
I have four rectangles of different colors and I need them to spawn ramdomly on four given points
. How to make them ramdomly spawn on points, I know, but how to make them spawn without repeating, I don’t know
. That is, the red cube spawned and it is larger can't spawn on the other 3 positions and these 4 positions need to have one object of each color
Answer the question
In order to leave comments, you need to log in
Colors in the list (List) and mix. Then take it out one by one.
private static Random rng = new Random();
public static void Shuffle<T>(this IList<T> list)
{
int n = list.Count;
while (n > 1) {
n--;
int k = rng.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
var shuffled = myList.OrderBy(x => Guid.NewGuid()).ToList();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question