Thank you for your help. I read some answers there and not all fit my simple script. Some freeze the engine !!
One of them was good but the problem is when I use bool to regenerate the numbers I double the values !! If you could solve this will be good.
List<int> xList = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
public List<int> deck = new List<int>();
void Update()
{
if (changeNumber == true)
{
foreach (int xInt in xList)
{
deck.Insert(Random.Range(0, deck.Count + 1), xInt);
}
changeNumber = false;
}
}
More performant and with FAR less memory churn, just use a basic Fisher-Yates shuffle. But make it properly as the Wikipedia pseudocode shows, without bugs
// take int in, create int-length list starting at offset, randomize it
public static List<int> createAndRandomizeList(int length, int offset)
{
List<int> tempCreateRandList = new List<int>();
for (int i = 0; i < length; i++)
{
tempCreateRandList.Add(i + offset);
}
for (int i = 0; i < tempCreateRandList.Count; i++)
{
int temp = tempCreateRandList[i];
int rand = Random.Range(i, tempCreateRandList.Count);
tempCreateRandList[i] = tempCreateRandList[rand];
tempCreateRandList[rand] = temp;
}
//Debug.Log("tempCreateRandList = " + string.Join(",", tempCreateRandList));
return tempCreateRandList;
}