Java Random Long random(long min, long max)

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

Description

Returns a random long number between the value min and the value max.

License

Apache License

Parameter

Parameter Description
min the minimum value.
max the maximum value.

Exception

Parameter Description
ArgumentMalformedException if the value <tt>min</tt>is greater than the value <tt>max</tt>

Return

a random long number between the value min and the value max.

Declaration

public static long random(long min, long max) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*w w w . j a  v a  2  s . c om*/
     * Returns a random long number between the value <tt>min</tt>
     * and the value <tt>max</tt>.
     * @param min the minimum value.
     * @param max the maximum value.
     * @return a random long number between the value <tt>min</tt>
     *       and the value <tt>max</tt>.
     * @throws ArgumentMalformedException if the value <tt>min</tt>
     *       is greater than the value <tt>max</tt>
     */
    public static long random(long min, long max) {
        if (min > max) {
            throw new ArithmeticException(
                    "min" + String.valueOf(min) + "Value min " + min + " must be lesser than value max " + max);
        }
        return (long) (Math.random() * (max - min) + min);
    }
}

Related

  1. randLong()
  2. randLong(long minimum, long maximum)
  3. randLong(long n)
  4. random(long begin, long end)
  5. random(long max)
  6. random(long range)
  7. randomHexOfLong(long max)
  8. randomLong()
  9. randomLong()