Skip to content

Instantly share code, notes, and snippets.

@viveknarang
Created October 5, 2017 20:37
Show Gist options
  • Save viveknarang/0bd9c956ac956bed5dee992ac061b9b3 to your computer and use it in GitHub Desktop.
Save viveknarang/0bd9c956ac956bed5dee992ac061b9b3 to your computer and use it in GitHub Desktop.
import java.util.Arrays;
import java.util.Random;
public class Test5 {
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9};
Random r = new Random();
int temp = 0, a = 0, b = 0;
for(int i = 0; i < numbers.length; i++) {
a = r.nextInt(numbers.length);
b = r.nextInt(numbers.length);
temp = numbers[a];
numbers[a] = numbers[b];
numbers[b] = temp;
}
System.out.println(Arrays.toString(numbers));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment