Java Random Int random_range(int x1, int x2)

Here you can find the source of random_range(int x1, int x2)

Description

Returns a random real number between x1 (inclusive) and x2 (exclusive).

License

Open Source License

Parameter

Parameter Description
x1 The inclusive
x2 The exclusive

Return

A random real number between x1 and x2

Declaration

public static int random_range(int x1, int x2) 

Method Source Code

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

public class Main {
    /**/*ww  w. j a va 2 s.com*/
     * Returns a random real number between x1 (inclusive) and x2 (exclusive).
     *
     * @param x1 The inclusive
     * @param x2 The exclusive
     * @return A random real number between x1 and x2
     */
    public static int random_range(int x1, int x2) {
        return (int) (Math.floor(x1 + (Math.random() * (x2 - x1))));
    }

    /**
     * Returns a random real number between 0 and x. The number is always
     * smaller than x.
     *
     * @param x The maximum range
     * @return A random real number
     */
    public static int random(int x) {
        return (int) (Math.floor(Math.random() * x));
    }
}

Related

  1. random(int range)
  2. random(int start, int end)
  3. random(int theRange)
  4. random(int x)
  5. random(int... array)
  6. randomActorId(int max)
  7. randomAlphaNum(int length)
  8. randomAlphanumeric(int count)
  9. randomAlphanumericString(int length)