Java Random Double randomRange(double min, double max)

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

Description

Returns a pseudorandom double within the given range.

License

BSD License

Parameter

Parameter Description
min The minimum inclusive value
max The maximum inclusive value

Return

The pseudorandom value

Declaration

public static double randomRange(double min, double max) 

Method Source Code

//package com.java2s;
/**// w w  w.ja v a 2 s .  co  m
 * CamanJ - Java Image Manipulation
 * Ported from the CamanJS Javascript library
 *
 * Copyright 2011, Ryan LeFevre
 * Licensed under the new BSD License
 * See LICENSE for more info.
 * 
 * Project Home: http://github.com/meltingice/CamanJ
 */

public class Main {
    /**
     * Returns a pseudorandom double within the given range.
     * 
     * @param min
     *            The minimum inclusive value
     * @param max
     *            The maximum inclusive value
     * @return The pseudorandom value
     */
    public static double randomRange(double min, double max) {
        return min + (Math.random() * ((max - min) + 1));
    }

    /**
     * Returns a pseudorandom int within the given range.
     * 
     * @param min
     *            The minimum inclusive value
     * @param max
     *            The maximum inclusive value
     * @return The pseudorandom value
     */
    public static int randomRange(int min, int max) {
        return min + (int) (Math.random() * ((max - min) + 1));
    }
}

Related

  1. randomFlip(double probTrue)
  2. randomIn(double in)
  3. randomInitialize(double[] base)
  4. randomInRange(double min, double max)
  5. randomPercent(double percent)
  6. randRealUniform(double minrange, double maxrange)