Last active
May 22, 2017 17:29
-
-
Save charlesreid1/edb9900f5ba2e06d67a028af2a7ea3d3 to your computer and use it in GitHub Desktop.
Fisher Yates - Code Fragment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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