Java Random Double randomDouble(double low, double high)

Here you can find the source of randomDouble(double low, double high)

Description

Returns a double value with a positive sign, greater than or equal to low and less than high.
Note: low limit is inclusive and high limit is exclusive.
The formula used in this method is:
randomDouble = Math.random() * (high - low) + low; (low: Inclusive, high: Exclusive)

License

Open Source License

Parameter

Parameter Description
low The low limit of the result (inclusive).
high The high limit of the result (exclusive).

Return

The random number in the given range.

Declaration

public static double randomDouble(double low, double high) 

Method Source Code

//package com.java2s;
/**//from  w w w . j a v  a  2s.co m
 * Project: JavaGE Library
 * Author:  Loukas Georgiou
 * Date:   14 Jan 2006
 * 
 * Copyright 2006, 2008 Loukas Georgiou.
 * This file is part of JavaGE (jGE) Library.
 * 
 * jGE Library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
    
 * jGE Library 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 General Public License for more details.
    
 * You should have received a copy of the GNU General Public License
 * along with jGE Library.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Returns a double value with a positive sign, greater than or equal to <code>low</code> 
     * and less than <code>high</code>.<br>
     * Note: <code>low</code> limit is inclusive and <code>high</code> limit is exclusive.<br>
     * The formula used in this method is:<br>
     * <code>randomDouble = Math.random() * (high - low) + low; (low: Inclusive, high: Exclusive)</code>
     *    
     * @param low The low limit of the result (inclusive).
     * @param high The high limit of the result (exclusive).
     * @return The random number in the given range.
     */
    public static double randomDouble(double low, double high) {
        return Math.random() * (high - low) + low;
    }
}

Related

  1. randomDouble()
  2. randomDouble()
  3. randomDouble()
  4. randomDouble()
  5. randomDouble()
  6. randomDouble(double min, double max)
  7. randomDouble(double min, double max)
  8. randomDouble(double min, double max)
  9. randomDouble(int min, int max)