fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. public static int numeroAleatorio(int a, int b) {
  8. final int min = Math.min(a, b);
  9. final int max = Math.max(a, b);
  10.  
  11. return min + (int)(Math.random() * ((max - min) + 1));
  12. }
  13.  
  14. public static int numeroAleatorio2(int a, int b) {
  15. final int min = Math.min(a, b);
  16. final int max = Math.max(a, b);
  17.  
  18. Random r = new Random();
  19. return min + r.nextInt((max - min) + 1);
  20. }
  21.  
  22. public static void main (String[] args) throws java.lang.Exception
  23. {
  24. System.out.println(numeroAleatorio(1000, 9999));
  25. }
  26. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
5053