generate Random integer within a range - Java java.util

Java examples for java.util:Random Int

Description

generate Random integer within a range

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int lRange = 2;
        int rRange = 2;
        System.out.println(genRandomNum(lRange, rRange));
    }/*w  ww  .ja  va  2 s .  co  m*/

    public static int genRandomNum(int lRange, int rRange) {
        return lRange + (int) (Math.random() * (rRange - lRange));
    }
}

Related Tutorials