• Source
    1. /*
    2.  
    3.  
    4. Date : 14 November 2013
    5. Author : Shivam Tiwari
    6. Organization : http://mycodedock.blogspot.in/
    7. Description : Random Integers between two ranges in Java
    8.  
    9.  
    10. */
    11.  
    12.  
    13. //import the Random library (class)
    14. import java.util.Random;
    15.  
    16. //main class
    17. public class Main{
    18.  
    19. //main function
    20. public static void main(String[] args){
    21.  
    22. //declaring variables
    23. int x;
    24. int MAXVAL = 50;
    25.  
    26. //create an object of the Random class named randomObj
    27. Random randomObj = new Random();
    28.  
    29. //run the loop 100 times from 0 to 99
    30. for(int i = 0; i < 99 ; i++){
    31.  
    32. //generate a random integer betwen 0 to 50 and store in x
    33. x = randomObj.nextInt(50);
    34.  
    35. //print the value in x
    36. System.out.println(x);
    37. }
    38. }
    39. }