Java Random randomInRange(double min, double max)

Here you can find the source of randomInRange(double min, double max)

Description

random In Range

License

Open Source License

Declaration

public static double randomInRange(double min, double max) 

Method Source Code

//package com.java2s;
/**//from  ww w. j a  va  2 s.  c  om
 * Copyright (c) 2014 Xiufeng Liu ( xiufeng.liu@uwaterloo.ca )
 * <p/>
 * This file is free software: you may copy, redistribute and/or modify it
 * under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 * <p/>
 * This file 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.
 * <p/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses.
 */

import java.util.*;

public class Main {
    protected static Random random = new Random();

    public static double randomInRange(double min, double max) {
        double range = max - min;
        double scaled = random.nextDouble() * range;
        return scaled + min;
    }
}

Related

  1. randomGreyLevels(double max, double min)
  2. randomIcon()
  3. randomID()
  4. randomId()
  5. randomIndices(Random r, int minCount, int maxCount)
  6. randomInsults()
  7. randomIntArray(int len, Random rand)
  8. randomIntegerList(int sz, int min, int max)
  9. randomIntegers(int sz)