package me.xdrop.jrand.generators.basics;

import me.xdrop.jrand.Generator;

public class NaturalGenerator extends Generator<Integer> {

    private int min;
    private int max;

    public NaturalGenerator() {
        this.max = Integer.MAX_VALUE;
        this.min = 0;
    }

    /**
     * Set the minimum value (inclusive)
     *
     * @param min The minimum value
     * @return
     */
    public NaturalGenerator min(int min) {
        this.min = min;
        return this;
    }

    /**
     * Set the maximum value to return (inclusive)
     *
     * @param max The maximum value to return (inclusive)
     * @return
     */
    public NaturalGenerator max(int max) {
        this.max = max;
        return this;
    }

    /**
     * Set a min/max range
     *
     * @param min Minimum value to be returned (inclusive)
     * @param max Maximum value to be returned (inclusive)
     * @return
     */
    public NaturalGenerator range(int min, int max) {
        min(min);
        max(max);
        return this;
    }

    @Override
    public Integer gen() {
        return random().randInt((max - min) + 1) + min;
    }
}

@@ -70,16 +70,68 @@
 rator;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 public c
@@ -1073,24 +1073,927 @@
 his;%0A    %7D%0A%0A
+    /**%0A     * Set a range starting from 0%0A     *%0A     * @param max Maximum value to be returned (inclusive)%0A     * @return%0A     */%0A    public NaturalGenerator range(int max) %7B%0A        min(0);%0A        max(max - 1);%0A        return this;%0A    %7D%0A%0A    /**%0A     * Retrieve n uniform samples from population without replacement%0A     * @param sampleSize Number of samples to retrieve%0A     * @param population The population size%0A     * @return A list of integer samples%0A     */%0A    public List%3CInteger%3E sample(int sampleSize, int population) %7B%0A        int t = 0, m =0;%0A        List%3CInteger%3E samples = new ArrayList%3C%3E();%0A%0A        while (m %3C sampleSize) %7B%0A            double u = random().randDouble();%0A            if ((population -t) * u %3E= sampleSize -m) %7B%0A                t++;%0A            %7D else %7B%0A                samples.add(t);%0A                t++; m++;%0A            %7D%0A        %7D%0A        return samples;%0A    %7D%0A%0A
     @Overrid

Add new range method