We would like to know how to count chance of duplication for random number within a range.
import java.util.Random; //from www .j a v a 2s . c o m public class Main { public static void main(String[] args) { for (int loop = 1; loop <= 1000; loop++) { int random1 = new Random().nextInt(100); int random2 = new Random().nextInt(100); if (random1 == random2) { System.out.println("Duplicate: "+random1); } } } }
The code above generates the following result.