Here you can find the source of generateRandomInteger(int aStart, int aEnd, Random aRandom)
Parameter | Description |
---|---|
aStart | a parameter |
aEnd | a parameter |
aRandom | a parameter |
public static int generateRandomInteger(int aStart, int aEnd, Random aRandom)
//package com.java2s; //License from project: Open Source License import java.util.Random; public class Main { /**// w w w . j a v a2 s.com * Erzeugt eine Zufallszahl * * @param aStart * @param aEnd * @param aRandom * @return */ public static int generateRandomInteger(int aStart, int aEnd, Random aRandom) { if (aStart > aEnd) { throw new IllegalArgumentException("Start cannot exceed End."); } // get the range, casting to long to avoid overflow problems long range = (long) aEnd - (long) aStart + 1; // compute a fraction of the range, 0 <= frac < range long fraction = (long) (range * aRandom.nextDouble()); int randomNumber = (int) (fraction + aStart); return randomNumber; } }