java randomly generate a number 0, 1, 2 code example Example: java random number generator in range int rand = ThreadLocalRandom.current().nextInt(x,y);