// 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.Random;

public class MF {
    public static final int M = 1;
    public static final int F = 2;
    private static final Random rng = new Random();
    public static double getUniformDist(double min, double max) {
        return min + (max - min) * rng.nextDouble();
    }
    public static double getNormalDist(double my, double s) {
        return my + s * rng.nextGaussian();
    }
    private static final int SAMPLE = 100000;
    public static void analyze(Model m) {
        System.out.println(m.getDecsription() + ":");
        for(Sex g : Sex.values()) {
            int[] cat = new int[4];
            for(int i = 0; i < SAMPLE; i++) {
                int skill = m.skill(g);
                if(m.chose(g, skill)) {
                    if(skill < 100) {
                        cat[0]++;
                    } else if(skill < 115) {
                        cat[1]++;
                    } else if(skill < 130) {
                        cat[2]++;
                    } else {
                        cat[3]++;
                    }
                }
            }
            System.out.printf("  %s : %4d %4d %4d %4d\n", g.toString(), cat[0], cat[1], cat[2], cat[3]);
        }
    }
    public static void main(String[] args) {
        analyze(new Model1());
        analyze(new Model2());
        analyze(new Model3());
        analyze(new Model4());
    }
}

enum Sex { M, F }

interface Model {
    public int skill(Sex g);
    public boolean chose(Sex g, int skill);
    public String getDecsription();
}

class Model1 implements Model {
    @Override
    public int skill(Sex g) {
        switch(g) {
        case M:
            return (int) MF.getNormalDist(105, 15);
        case F:
            return (int) MF.getNormalDist(95, 15);
        default:
            throw new RuntimeException("Illegal value");
        }
    }
    @Override
    public boolean chose(Sex g, int skill) {
        return skill > 100 ? MF.getUniformDist(0, 1) < 0.1 : false;
    }
    @Override
    public String getDecsription() {
        return "Model: F less skilled, identical limit to chose";
    }
}

class Model2 implements Model {
    @Override
    public int skill(Sex g) {
        switch(g) {
        case M:
            return (int) MF.getNormalDist(105, 15);
        case F:
            return (int) MF.getNormalDist(95, 15);
        default:
            throw new RuntimeException("Illegal value");
        }
    }
    @Override
    public boolean chose(Sex g, int skill) {
        return skill > 100 ? MF.getUniformDist(0, 1) < 0.1 : MF.getUniformDist(0, 1) < 0.01;
    }
    @Override
    public String getDecsription() {
        return "Model: F less skilled, identical limit to chose (with bad choices)";
    }
}

class Model3 implements Model {
    @Override
    public int skill(Sex g) {
        return (int) MF.getNormalDist(100, 15);
    }
    @Override
    public boolean chose(Sex g, int skill) {
        switch(g) {
        case M:
            return skill > 95 ? MF.getUniformDist(0, 1) < 0.1 : false;
        case F:
            return skill > 105 ? MF.getUniformDist(0, 1) < 0.1 : false;
        default:
            throw new RuntimeException("Illegal value");
        }
    }
    @Override
    public String getDecsription() {
        return "Model: identical skill, F has higher limit to chose";
    }
}

class Model4 implements Model {
    @Override
    public int skill(Sex g) {
        return (int) MF.getNormalDist(100, 15);
    }
    @Override
    public boolean chose(Sex g, int skill) {
        switch(g) {
        case M:
            return skill > 95 ? MF.getUniformDist(0, 1) < 0.1 : MF.getUniformDist(0, 1) < 0.01;
        case F:
            return skill > 105 ? MF.getUniformDist(0, 1) < 0.1 : MF.getUniformDist(0, 1) < 0.01;
        default:
            throw new RuntimeException("Illegal value");
        }
    }
    @Override
    public String getDecsription() {
        return "Model: identical skill, F has higher limit to chose (with bad choices)";
    }
}
