I'm trying to randomly get a specific integer (1) from a 2D array list filled with 0's and not many 1's. I made this, and it works:
while (wallsList[randomX, randomY] != 1)
{
randomX = randomizer.Next(34);
randomY = randomizer.Next(34);
}
The downside of it, it's that it takes too much time to just find one time the int (1), and I have to do this process over 1000 times since new 1's get added and removed to the 2D array each time. It takes about 3m to launch my program so I would like to know if there is an optimized version of this, I searched a lot and only found this solution for 1D arrays. Thanks for your time.
O(infinity). That's not a good thing. And you say "I searched a lot and only found this solution for 1D arrays." what solution are you referring to?