mardi 29 mars 2016

Picking from list randomly according to Pareto Principle

I have a List<T> and try to randomly pick items according to Pareto Principle, so first 20% items will be picked 80% times, and 80% remaining items will be picked 20% times. So far I have a simple implementation:

static <T> T pickPareto(List<T> list) {
    int n = list.size();
    int first = n * 0.2;
    return rnd.next() < 0.8            
           ? list.get(rnd.nextInt(first))                // pick one of first 20%
           : list.get(first + rnd.nextInt(n - first));   // pick one of remaining 80%
}

It works well, but results a step function of distribution.

Does anyone know how to select items according to smooth distribution (maybe not exactly Pareto, but holding 20/80 property)?




Aucun commentaire:

Enregistrer un commentaire