Java Random random(int min, int max)

Here you can find the source of random(int min, int max)

Description

Returns a random number

License

Open Source License

Declaration

public static int random(int min, int max) 

Method Source Code


//package com.java2s;
import java.util.*;

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

    /**/*www.j  a va 2s. co  m*/
     * Returns a random number
     */
    public static int random(int min, int max) {
        //      return ((int)(Math.random() * (1 + max - min))) + min;
        if (max - min == 0) {
            return min;
        }

        int rmin = Math.min(max, min);
        int rmax = Math.max(max, min);

        return random.nextInt(1 + rmax - rmin) + rmin;
        //      return ((int)(random.nextFloat() * (1 + max - min))) + min;

    }

    public static float random() {
        return random.nextFloat();
    }
}

Related

  1. random()
  2. random(E[] elements)
  3. random(final char[] chars)
  4. random(float min, float max)
  5. random(float theStart, float theEnd)
  6. random(List list, Random random)
  7. random4DigitNumber()
  8. random_g729()
  9. random_g729()