Java Random Double randomDouble(double min, double max)

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

Description

random Double

License

Open Source License

Declaration

public static double randomDouble(double min, double max) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

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

    public static double randomDouble(double min, double max) {
        return Math.random() < 0.5 ? ((1 - Math.random()) * (max - min) + min)
                : (Math.random() * (max - min) + min);
    }//from  w  w  w.j  av  a2s .  c  o m

    /**
     * Returns a random number between 0 (inclusive) and the specified value (inclusive).
     */
    static public final int random(int range) {
        return random.nextInt(range + 1);
    }

    /**
     * Returns a random number between start (inclusive) and end (inclusive).
     */
    static public final int random(int start, int end) {
        return start + random.nextInt(end - start + 1);
    }

    /**
     * Returns random number between 0.0 (inclusive) and 1.0 (exclusive).
     */
    static public final float random() {
        return random.nextFloat();
    }

    /**
     * Returns a random number between 0 (inclusive) and the specified value (exclusive).
     */
    static public final float random(float range) {
        return random.nextFloat() * range;
    }

    /**
     * Returns a random number between start (inclusive) and end (exclusive).
     */
    static public final float random(float start, float end) {
        return start + random.nextFloat() * (end - start);
    }
}

Related

  1. randomDouble()
  2. randomDouble()
  3. randomDouble(double low, double high)
  4. randomDouble(double min, double max)
  5. randomDouble(double min, double max)
  6. randomDouble(int min, int max)
  7. randomDouble(int start, int end)
  8. randomDoubleArray(final int mDimensionality)
  9. randomDoubleArray(int len)