Skip to content

Instantly share code, notes, and snippets.

@msturgill
Created November 21, 2013 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msturgill/7574538 to your computer and use it in GitHub Desktop.
Save msturgill/7574538 to your computer and use it in GitHub Desktop.
Fisher-Yates Shuffle
public void Shuffle()
{
int n = this.Count;
byte[] box = new byte[1];
while (n > 1)
{
do Utility.RandomBytes(box);
while (!(box[0] < n * (Byte.MaxValue / n)));
int k = (box[0] % n);
n--;
Swap(n, k);
}
Callback( OnShuffle );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment