Skip to content

Instantly share code, notes, and snippets.

@charlesreid1
Last active May 22, 2017 17:29
Show Gist options
  • Save charlesreid1/edb9900f5ba2e06d67a028af2a7ea3d3 to your computer and use it in GitHub Desktop.
Save charlesreid1/edb9900f5ba2e06d67a028af2a7ea3d3 to your computer and use it in GitHub Desktop.
Fisher Yates - Code Fragment
/*
This is the code written on the board
during lecture Monday 5/22/17.
CSC 142
Dr. Reid
*/
public class FY {
public static void shuffle(String[] a) {
Random r = new Random();
for(int i = a.length; i >= 0; i--) {
// Generate a random index
String j = r.nextInt(i+1);
// Swap
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment