c# - Randomly pick a specific int from a 2D Array -


i'm trying randomly specific integer (1) 2d array list filled 0's , not many 1's. made this, , works:

while (wallslist[randomx, randomy] != 1) {     randomx = randomizer.next(34);     randomy = randomizer.next(34); } 

the downside of it, it's takes time find 1 time int (1), , have process on 1000 times since new 1's added , removed 2d array each time. takes 3m launch program know if there optimized version of this, searched lot , found solution 1d arrays. time.

you have sparse array. why not represent list of x/y int pairs? then, if x/y int pair in list, it's 1, if not, it's 0.

then, find random value/cell containing 1, pick random value list.

you use list like

new list <tuple<int, int>> { new tuple<int, int>(1, 5), new tuple<int, int>(2, 7) } 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo