get Random integer within range - Java java.util

Java examples for java.util:Random Int

Description

get Random integer within range

Demo Code


//package com.java2s;
import java.util.Random;

public class Main {
    public static void main(String[] argv) throws Exception {
        int range = 2;
        System.out.println(getRandom(range));
    }//from   w w w .j  a va  2  s.  c  o  m

    final static Random ran = new Random();

    public static int getRandom(int range) {
        return ran.nextInt(range);
    }
}

Related Tutorials