title: How to randomise the input array before apply different sorting algorithms in Java?
body: <p>I have one input array and I want to randomize the array for each sorting algorithms.</p>
  
  <p>Example:</p>
  
  <pre><code>import sort.bub;
  import sort.ins;
  import sort.sel;
  
  import java.util.Arrays;
  import java.util.Random;
  
  public class sorting{
  
      public static int[] arr = new int[10];
      public static bub bubble = new bub();
      public static sel selection = new sel();
      public static ins insertion = new ins();
  
  
      public static void main(String[] args) {
  
          getMathRandom();
          bubble.bub(arr);
          getMathRandom();
          insertion.ins(arr);
          getMathRandom();
          selection.sel(arr);
      }
  
  
      public static void getRandom(int[] arr) {
          Random random = new Random();
          for (int i = 0; i &lt; arr.length; i++) {
              arr[i] = random.nextInt();
              //System.out.println(arr[i]);
          }
          System.out.println(Arrays.toString(arr));
  
      }
  
      private static void getMathRandom() {
  
          for (int j = 0; j &lt; arr.length; j++) {
              int number = (int) (Math.random() * 1000);
              arr[j] = number;
          }
          System.out.println("Random  " + Arrays.toString(arr));
          System.out.println("");
      }   
  }
  </code></pre>
  
  <p>bub.java</p>
  
  <pre><code>import java.util.Arrays;
  public class bub {
      public bub() {
      }
     public void bub(int[] arr) {
          System.out.println("bubble sort");
          for (int i = arr.length - 1; i &gt;= 0; i--) {
              System.out.println(Arrays.toString(arr));
              for (int index = 0; index &lt; i; index++) {
                  if (arr[index] &gt; arr[index + 1]) {
                      int tmp = arr[index];
                      arr[index] = arr[index + 1];
                      arr[index + 1] = tmp;
                  }
              }
             // System.out.println(Arrays.toString(arr));
          }
          System.out.println("");
      }
  }
  </code></pre>
  
  <p>sel.java</p>
  
  <pre><code>import java.util.Arrays;
  public class sel {
      public sel() {
      }
      public void sel(int[] arr) {
          System.out.println("selection sort: ");
          for (int i = 0; i &lt; arr.length - 1; i++) {
              System.out.println(Arrays.toString(arr));
  
              for (int index = i + 1; index &lt; arr.length; index++) {
                  if (arr[i] &gt; arr[index]) {
                      int tmp = arr[index];
                      arr[index] = arr[i];
                      arr[i] = tmp;
                  }
              }
  //            System.out.println(Arrays.toString(arr));
          }
          System.out.println("");
      }
  }
  </code></pre>
  
  <p>ins.java</p>
  
  <pre><code>import java.util.Arrays;
  public class ins {
      public ins() {
      }
      public void ins(int[] arr) {
          System.out.println("insertion sort: ");
          for (int i = 1; i &lt; arr.length; i++) {
              System.out.println(Arrays.toString(arr));
  
              int newElement = arr[i];
              int location = i - 1;
              while (location &gt;= 0 &amp;&amp; arr[location] &gt; newElement) {
                  arr[location + 1] = arr[location];
                  location--;
              }
              arr[location + 1] = newElement;
          }
  
          System.out.println("");
      }
  }
  </code></pre>
  
  <p>output</p>
  
  <pre><code>Random  [928, 469, 309, 30, 344, 230, 924, 628, 319, 275]
  
  bubble sort
  [928, 469, 309, 30, 344, 230, 924, 628, 319, 275]
  [469, 309, 30, 344, 230, 924, 628, 319, 275, 928]
  [309, 30, 344, 230, 469, 628, 319, 275, 924, 928]
  [30, 309, 230, 344, 469, 319, 275, 628, 924, 928]
  [30, 230, 309, 344, 319, 275, 469, 628, 924, 928]
  [30, 230, 309, 319, 275, 344, 469, 628, 924, 928]
  [30, 230, 309, 275, 319, 344, 469, 628, 924, 928]
  [30, 230, 275, 309, 319, 344, 469, 628, 924, 928]
  [30, 230, 275, 309, 319, 344, 469, 628, 924, 928]
  [30, 230, 275, 309, 319, 344, 469, 628, 924, 928]
  
  Random  [909, 584, 169, 129, 175, 297, 733, 473, 619, 745]
  
  insertion sort: 
  [909, 584, 169, 129, 175, 297, 733, 473, 619, 745]
  [584, 909, 169, 129, 175, 297, 733, 473, 619, 745]
  [169, 584, 909, 129, 175, 297, 733, 473, 619, 745]
  [129, 169, 584, 909, 175, 297, 733, 473, 619, 745]
  [129, 169, 175, 584, 909, 297, 733, 473, 619, 745]
  [129, 169, 175, 297, 584, 909, 733, 473, 619, 745]
  [129, 169, 175, 297, 584, 733, 909, 473, 619, 745]
  [129, 169, 175, 297, 473, 584, 733, 909, 619, 745]
  [129, 169, 175, 297, 473, 584, 619, 733, 909, 745]
  
  Random  [404, 277, 798, 863, 163, 163, 984, 638, 248, 561]
  
  selection sort: 
  [404, 277, 798, 863, 163, 163, 984, 638, 248, 561]
  [163, 404, 798, 863, 277, 163, 984, 638, 248, 561]
  [163, 163, 798, 863, 404, 277, 984, 638, 248, 561]
  [163, 163, 248, 863, 798, 404, 984, 638, 277, 561]
  [163, 163, 248, 277, 863, 798, 984, 638, 404, 561]
  [163, 163, 248, 277, 404, 863, 984, 798, 638, 561]
  [163, 163, 248, 277, 404, 561, 984, 863, 798, 638]
  [163, 163, 248, 277, 404, 561, 638, 984, 863, 798]
  [163, 163, 248, 277, 404, 561, 638, 798, 984, 863]
  </code></pre>
  
  <p>i want the array just one random array, but with three different sorting. I tried to use only one getmathrandom but only one sort that runs the other only shows the results of the top sorting. how would I do that? Or any other solution I'd appreciate.</p>