Tuesday, October 9, 2012

Java Random number generation of 4 digits

import java.util.Random;

System.out.println("***** Generating Random Number of 4 digit *****");
Random random = new Random();
for(int i=0;i<100;i++){
    long fraction = (long)(1000 * random.nextDouble());
    int PIN= (int)(fraction + 1000);
    System.out.println(PIN);
 }

0 comments:

Post a Comment