Randomly shuffling an array

Take two random numbers between 0 and the length of the array (bounds inclusive) and swap the values.

This example shows you a method that can take an array of any type and just swaps references around.

Main.java:

import java.util.*;
import java.io.*;
import java.lang.reflect.*;
 
public class Main
{
   public static void main(String []args) {
      int[] arr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
  
      System.out.print("Before:nt");
      printArray(arr);
 
      shuffleArray(arr); 
 
      System.out.print("After:nt");
      printArray(arr);
   }
  
   public static void printArray(int []arr) { 
      for (int i=0; i<arr.length; i++) {
         System.out.print(arr[i] + " ");
      }
      System.out.println();
   }
 
   public static void shuffleArray(Object arr) {
      Random r = new Random();
      for (int i=0; i<100; i++) {
         int r1 = Math.abs(r.nextInt() % 10);
         int r2 = Math.abs(r.nextInt() % 10);
         Object el0 = Array.get(arr, r1);
         Object el1 = Array.get(arr, r2);
         Array.set(arr, r2, el0);
         Array.set(arr, r1, el1);
      }
   }
}

outputs:

Before:
	0 1 2 3 4 5 6 7 8 9 
After:
	1 4 7 3 5 9 6 2 8 0