Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Arrays;
import java.util.Random;

public class Main {
    public static void main(String args[]) {
        int[] solutionArray = { 1, 2, 3, 4, 5, 6 };
        shuffleArray(solutionArray);
        System.out.println(Arrays.toString(solutionArray));
    }

    static void shuffleArray(int[] ar) {
        Random rnd = new Random();
        for (int i = ar.length - 1; i > 0; i--) {
            int index = rnd.nextInt(i + 1);
            // Simple swap
            int a = ar[index];
            ar[index] = ar[i];
            ar[i] = a;
        }
    }
}