Answers for "random class in java"

1

random class in java

import java.util.Random;
public class JavaRandomClassExample
{
   public static void main(String[] args)
   {
      Random rand = new Random();
      System.out.println(rand.nextInt(10));
      System.out.println(rand.nextBoolean());
      System.out.println(rand.nextDouble());
      System.out.println(rand.nextFloat());
      System.out.println(rand.nextGaussian());
      byte[] bytes = new byte[10];
      rand.nextBytes(bytes);
      System.out.printf("[");
      for(int a = 0; a < bytes.length; a++)
      {
         System.out.printf("%d ", bytes[a]);
      }
      System.out.printf("]\n");
      System.out.println(rand.nextLong());  
      System.out.println(rand.nextInt());
      long seed = 55;
      rand.setSeed(seed);
   }
}
Posted by: Guest on November-04-2021
13

random java

import java.util.Random();
Random <name> = new Random();
<variable> = <name>.nextInt(<excuslive top limit>);
Posted by: Guest on December-28-2019
0

Generate Random number using random class in Java

import java.util.Random;
class GenerateRandom {
    public static void main( String args[] ) {
      Random rand = new Random(); //instance of random class
      int upperbound = 25;
        //generate random values from 0-24
      int int_random = rand.nextInt(upperbound); 
      double double_random=rand.nextDouble();
      float float_random=rand.nextFloat();
      
      System.out.println("Random integer value from 0 to" + (upperbound-1) + " : "+ int_random);
      System.out.println("Random float value between 0.0 and 1.0 : "+float_random);
      System.out.println("Random double value between 0.0 and 1.0 : "+double_random);
    }
}
Posted by: Guest on August-25-2021
-2

random class

Random rd = new Random(); //Create an instance of Random Class
int x = rd.Next(1,50);  //Generates a random number of int datatype between 1 and 50
Console.WriteLine(x); //Print the random number on Console
Posted by: Guest on April-28-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language