Here you can find the source of generateRandomInteger(int start, int end)
Parameter | Description |
---|---|
start | The smallest possible number that can be generated. |
end | The largest possible number that can be generated. |
public static int generateRandomInteger(int start, int end)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { private static Random _randomNumberGenerator; /**/*from w w w.jav a 2 s. c om*/ * Generates a random integer in the interval [start, end] (interval includes both start and end) * and returns it. * @param start The smallest possible number that can be generated. * @param end The largest possible number that can be generated. * @return A randomly generated integer. */ public static int generateRandomInteger(int start, int end) { int range = end - start; if (_randomNumberGenerator == null) _randomNumberGenerator = new Random(); if (range > 0) return _randomNumberGenerator.nextInt(range) + start; return start; } }