Here you can find the source of rand(int lo, int hi)
Parameter | Description |
---|---|
lo | Description of the Parameter |
hi | Description of the Parameter |
public static int rand(int lo, int hi)
//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; } }