random Value From Array - Android java.util

Android examples for java.util:Random

Description

random Value From Array

Demo Code


//package com.java2s;

import java.util.Random;

public class Main {
    public static int randomValueFromArray(Random random, int[] arr) {
        return arr[randomNumberInRange(random, 0, arr.length - 1)];
    }/*from  w w  w  .java2  s.  c o m*/

    public static int randomNumberInRange(Random random, int minX, int maxX) {
        return minX + random.nextInt(maxX - minX + 1);
    }
}

Related Tutorials