/**
 * 
 */
package io.github.benas.jpopulator.randomizers;

import io.github.benas.jpopulator.api.Randomizer;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;

/**
 * A custom randomizer that generates a list of random values from another {@link Randomizer}
 * @author Eric Taix (eric.taix@gmail.com)
 */
public class ListRandomizer<T> implements Randomizer<Collection<T>> {

    private static final Random RANDOM = new Random();
    
	private Randomizer<T> elementRandomizer;
	private int min;
	private int max;
	
	/**
	 * Default constructor which will generate a list with a random number of element. Each element is generated by the {@link Randomizer} parameter 
	 * @param elementRandomizer
	 */
	public ListRandomizer(Randomizer<T> elementRandomizer) {
        this(elementRandomizer, 0, (byte) Math.abs((Byte) (byte) (RANDOM.nextInt())));
	}
	
	/**
	 * Constructor which will generate a list with a fixed nb of elements. Each element is generated by the {@link Randomizer} parameter 
	 * @param elementRandomizer The randomizer used to generate each element
	 * @param nb The number of elements in the list to generate
	 */
	public ListRandomizer(Randomizer<T> elementRandomizer, int nb) {
		this(elementRandomizer, 0, nb);
	}
	
	/**
	 * Constructor which will generate a list with a random nb of elements. Each element is generated by the {@link Randomizer} parameter 
	 * @param elementRandomizer The randomizer used to generate each element
	 * @param min The minimum number of elements in the list to generate
	 * @param max The maximum number of elements in the list to generate
	 */
	public ListRandomizer(Randomizer<T> elementRandomizer, int min, int max) {
		this.elementRandomizer = elementRandomizer;
		this.min = min;
		this.max = max;
	}
	
	@Override
	public Collection<T> getRandomValue() {
		List<T> result = new ArrayList<T>();
		int nb = RANDOM.nextInt(max-min > 0 ? max-min : 1) + min;
		for(int i = 0; i < nb; i++) {
			result.add(elementRandomizer.getRandomValue());
		}
		return result;
	}

}

@@ -1275,17 +1275,18 @@
 omizer, 
-0
+nb
 , nb);%0A%09
@@ -1789,16 +1789,138 @@
  = min;%0A
+%09%09assert max %3E= min : %22The maximum number of occurences should be higher or equal to the minimum number of occurrences.%22;%0A
 %09%09this.m
@@ -1927,16 +1927,20 @@
 ax = max
+ + 1
 ;%0A%09%7D%0A%09%0A%09
@@ -2029,16 +2029,16 @@
 t%3CT%3E();%0A
+
 %09%09int nb
@@ -2066,26 +2066,8 @@
 -min
- %3E 0 ? max-min : 1
 ) + 

Fix the random number of elements for ListRandomizer