0
Q:

java random

import java.util.Random;

Random rand = new Random();

// Obtain a number between [0 - 49].
int n = rand.nextInt(50);

// Add 1 to the result to get a number from the required range
// (i.e., [1 - 50]).
n += 1;
28
import java.util.Random;

class scratch{
    public static void main(String[] args) {
        Random rand = new Random();
        System.out.println( rand.nextInt(5) );
        //prints a random Int between 0 - 4 (including 0 & 4);
    }
}
9
import java.util.Random();
Random <name> = new Random();
<variable> = <name>.nextInt(<excuslive top limit>);
8
Random random = new Random();   
// Generates random integers 0 to 49  
int x = random.nextInt(50);  
3
import java.util.Random;
public class Example {
   public static void main(String[] args) {
      Random rd = new Random(); // creating Random object
      System.out.println(rd.nextFloat()); // displaying a random float value between 0.0 and 1.0
   }
}
2
int nombreAleatoire = Min + (int)(Math.random() * ((Max - Min) + 1));
2
Random rand = new Random(System.currentTimeMillis());
1
import java.util.Arrays;

public class HelloWorld {
  public static void main(String[] args) {
    
    // init array
    String[] family = new String[] {"Nova", "Mpo", "Moms", "Shorty", "Charlie"};
    
    // print array string
    System.out.println(Arrays.toString(family));
    
 
  }
}
0

New to Communities?

Join the community