thorax232

Java - Generate Random Number (Libraries)

Nov 23rd, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.54 KB | None | 0 0
  1. import java.util.Random;
  2.  
  3. public class TestRandom {
  4.     public static void main(String[] args) {
  5.        
  6.         // Generates random object with seed of 1000,
  7.         // two objects with same seed generate same sequence
  8.         // of numbers
  9.         Random random = new Random(1000);
  10.        
  11.         int count = 0;
  12.        
  13.         // nextInt prints numbers between 0 and 100
  14.         for(int i = 0; i < 60; i++) {
  15.             System.out.print(random.nextInt(100) + " ");
  16.             count++;
  17.            
  18.             // Print 10 results per line
  19.             if(count == 10) {
  20.                 System.out.println();
  21.                 count = 0;
  22.             }
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment