// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class Collision {
    private static Random rng = new Random();
    public static int test1(int nusers, int secs) {
        int ncol = 0;
        Set<Long> set = new HashSet<Long>();
        for(int i = 0; i < nusers; i++) {
            long v = (0x7FFFFFFFFFFFFFFFL & rng.nextLong()) % (secs * 1000000L);
            if(set.contains(v)) {
                ncol++;
            } else {
                set.add(v);
            }
        }
        return ncol;
    }
    private static int REP = 1000;
    public static void test(int nusers, int secs) {
        double sum = 0;
        double count = 0;
        for(int i = 0; i < REP; i++) {
            int col = test1(nusers, secs); 
            sum += col;
            count += (col > 0 ? 1 : 0);
        }
        System.out.println(sum/REP + " " + count/REP);
    }
    public static void main(String[] args) {
        test(100000, 3600);
    }
}
