Here you can find the source of randomInt(int ceil)
Parameter | Description |
---|---|
ceil | Max value for the random number |
public static int randomInt(int ceil)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**//from w w w .jav a 2 s.c o m * Returns a random number between 0 and the int you pass * * @param ceil Max value for the random number * @return Random number */ public static int randomInt(int ceil) { Random m = new Random(Calendar.getInstance().getTimeInMillis()); Random e = new Random(m.nextInt()); return (int) (e.nextFloat() * (ceil + 1)); } public static int randomInt(int floor, int ceil) { return randomInt(Calendar.getInstance().getTimeInMillis(), floor, ceil); } public static int randomInt(long seed, int floor, int ceil) { Random m = new Random(seed); Random e = new Random(m.nextInt()); return (int) (e.nextFloat() * (ceil - floor + 1)) + floor; } }