generate random number using random class in java

Solutions on MaxInterview for generate random number using random class in java by the best coders in the world

showing results for - "generate random number using random class in java"
Luigi
08 Jan 2017
1import java.util.Random;
2class GenerateRandom {
3    public static void main( String args[] ) {
4      Random rand = new Random(); //instance of random class
5      int upperbound = 25;
6        //generate random values from 0-24
7      int int_random = rand.nextInt(upperbound); 
8      double double_random=rand.nextDouble();
9      float float_random=rand.nextFloat();
10      
11      System.out.println("Random integer value from 0 to" + (upperbound-1) + " : "+ int_random);
12      System.out.println("Random float value between 0.0 and 1.0 : "+float_random);
13      System.out.println("Random double value between 0.0 and 1.0 : "+double_random);
14    }
15}