Source Code : Generating random numbers

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

Generating random numbers

    
/*
Java Programming for Engineers
Julio Sanchez
Maria P. Canton


ISBN: 0849308100
Publisher: CRC Press
*/


// Java for Engineers
//Filename: RandNum
//Reference: Chapter 23
//Description:
//         Generating random numbers


class RandNum {
  public static void main(String[] args) {
    int num;
    int[] dist = new int[10]; // Storage for distribution

    // Generate 10000 random numbers using Math.random()
    for (int x = 0; x < 10000; x++) {
      num = (int) (Math.floor(Math.random() * 10));
      dist[num]++;
    }
    // Display distribution of random integers in the range
    // 0 to 9
    System.out.println("Distribution using Math.random() ");
    for (int k = 0; k < 10; k++)
      System.out.print(k + "	");
    // Display results
    for (int y = 0; y < 10; y++) {
      System.out.print(dist[y] + "	");
    }
    System.out.println();
  }
}


           
         
    
    
    
  

Thank with us