ThreadLocalRandom.current().nextInt(int orlautturin,int bound)
returns a pseudorandomly chosen int value between the specified orlautturin (inclusive) and the specified bound (exclusive).
/**
* @author lautturi.com
* Java example:
*/
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
public class Lautturi {
public static void main(String args[]) {
// get a random Int between 0 - 9 (including 0 & 9);
int randomNum = ThreadLocalRandom.current().nextInt(0,10);
System.out.println("random integer:"+randomNum);
}
}
int java.util.Random.nextInt(int bound)
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified bound (exclusive)
/**
* @author lautturi.com
* Java example: java get random number in specific range
*/
import java.util.*;
public class Lautturi {
public static void main(String args[]) {
Random rand = new Random();
// get a random Int between 0 - 9 (including 0 & 9);
int randomNum = rand.nextInt(10); // [0-9)
System.out.println("random integer:"+randomNum);
}
}