java random number generator within given number code example Example: java random number generator in range int rand = ThreadLocalRandom.current().nextInt(x,y);