Here you can find the source of randBetween(int min, int max)
Parameter | Description |
---|---|
min | the mininum returned value |
max | the maxinum returned value |
min
and max
(both included)
public static int randBetween(int min, int max)
//package com.java2s; //License from project: Apache License public class Main { /**/* w ww. j a v a 2s .c om*/ * @param min the mininum returned value * @param max the maxinum returned value * @return a random integer between <code>min</code> and <code>max</code> (both included) */ public static int randBetween(int min, int max) { if (max < min) throw new IllegalArgumentException("'max' < 'min' is not legal"); return (int) (Math.random() * (max - min) + min); } public static long randBetween(long min, long max) { if (max < min) throw new IllegalArgumentException("'max' < 'min' is not legal"); return (long) (Math.random() * (max - min) + min); } public static float randBetween(float min, float max) { if (max < min) throw new IllegalArgumentException("'max' < 'min' is not legal"); return (float) (Math.random() * (max - min) + min); } }