Here you can find the source of random(double low, double high)
Parameter | Description |
---|---|
low | the low bound |
high | the high bound |
public static double random(double low, double high)
//package com.java2s; /**/* w w w . j a v a 2 s.c o m*/ * This file is part of PaxmlCore. * * PaxmlCore is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * PaxmlCore is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with PaxmlCore. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Create a random number between two double bounds. * * @param low * the low bound * @param high * the high bound * @return the random number */ public static double random(double low, double high) { if (low == high) { return low; } else if (low > high) { double tmp = low; low = high; high = tmp; } double range = high - low; return low + Math.random() * range; } /** * Create a random number between two long bounds. * * @param low * the low bound * @param high * the high bound * @return the random number */ public static long random(long low, long high) { return Math.round(random(low + 0.0, high)); } }