Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.graphics.PointF;

import android.os.Build;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class Main {
    public static void shuffleArray(PointF[] ar, int length) {
        // If running on Java 6 or older, use `new Random()` on RHS
        Random rnd;
        if (Build.VERSION.SDK_INT >= 21)
            rnd = ThreadLocalRandom.current();
        else
            rnd = new Random();

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