Java Random Byte rand(int lo, int hi)

Here you can find the source of rand(int lo, int hi)

Description

Returns a random number that falls within the specified range

License

Open Source License

Parameter

Parameter Description
lo Description of the Parameter
hi Description of the Parameter

Return

Description of the Return Value

Declaration

public static int rand(int lo, int hi) 

Method Source Code

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

import java.util.Random;

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

    /**/*  w  w w. j  a  v a 2 s .co  m*/
     * Returns a random number that falls within the specified range
     *
     * @param lo Description of the Parameter
     * @param hi Description of the Parameter
     * @return Description of the Return Value
     */
    public static int rand(int lo, int hi) {
        int n = hi - lo + 1;
        int i = rn.nextInt() % n;
        if (i < 0) {
            i = -i;
        }
        return lo + i;
    }
}

Related

  1. generateRandomByte()
  2. rand(int bit)
  3. rand(int lbound, int ubound)
  4. rand(int lo, int hi)
  5. rand(int lo, int hi)
  6. Rand(int lo, int hi)
  7. rand(int max)
  8. randByte()
  9. randomByte()