Here you can find the source of random_range(int x1, int x2)
Parameter | Description |
---|---|
x1 | The inclusive |
x2 | The exclusive |
public static int random_range(int x1, int x2)
//package com.java2s; //License from project: Open Source License public class Main { /**/*ww w. j a va 2 s.com*/ * Returns a random real number between x1 (inclusive) and x2 (exclusive). * * @param x1 The inclusive * @param x2 The exclusive * @return A random real number between x1 and x2 */ public static int random_range(int x1, int x2) { return (int) (Math.floor(x1 + (Math.random() * (x2 - x1)))); } /** * Returns a random real number between 0 and x. The number is always * smaller than x. * * @param x The maximum range * @return A random real number */ public static int random(int x) { return (int) (Math.floor(Math.random() * x)); } }