Answers for "java how to generate a number from 0 and 2"

1

how to get random number in java in range

package com.mkyong.example.test;

import java.util.Random;

public class TestRandom {

    public static void main(String[] args) {

        for (int i = 0; i < 10; i++) {
            System.out.println(getRandomNumberInRange(5, 10));
        }

    }

    private static int getRandomNumberInRange(int min, int max) {

        if (min >= max) {
            throw new IllegalArgumentException("max must be greater than min");
        }

        Random r = new Random();
        return r.nextInt((max - min) + 1) + min;
    }

}
Posted by: Guest on January-20-2021
2

java random number generator in range

int rand = ThreadLocalRandom.current().nextInt(x,y);
Posted by: Guest on May-12-2020

Code answers related to "java how to generate a number from 0 and 2"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language