I have two dimensional array. I want to pick a slot at random, and continue to do so never picking the same slot twice until I have finally picked all slots (so nothing random about the last pick of course). Is there a well known algorithm for doing this? I'm using C#, but obviously this is more about algorithms than any particular platform. Yes, 'the big book' is on my purchase list :)
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
Take a look at the Fisher-Yates shuffle. It's designed to pick a random permutation from a set.
Assuming your array is like this:
This should work fine.
I did this for numbers
Using the Fisher-Yates shuffle algorithm as mentioned before (in O(n) time)