Contact: aviboots(AT)netvision.net.il
41,260 questions
53,769 answers
573 users
import java.util.concurrent.ThreadLocalRandom; public class MyClass { public static void main(String args[]) { int min = 17; int max = 31; int number = ThreadLocalRandom.current().nextInt(min, max + 1); System.out.println(number); } } /* run: 25 */
public class MyClass { public static void main(String args[]) { int min = 17; int max = 31; int number = min + (int)(Math.random() * ((max - min) + 1)); System.out.println(number); } } /* run: 29 */
import java.util.Random; public class MyClass { public static void main(String args[]) { Random random = new Random(); int min = 17; int max = 31; int number = random.nextInt(max + 1 - min) + min; System.out.println(number); } } /* run: 17 */