package tools;

/**
 *
 * @author Flav od. Duncan !?!?
 */
public class IntegerUtil {
    public static int rand(int min, int max) {
        return (int) (Math.random() * (max - min + 1) + min);
    }

    public static String dice(String arg) throws Exception{
        StringBuilder buffer = new StringBuilder();
        String[] w = arg.toLowerCase().split("w");
        int wuerfel = Integer.parseInt(w[0]);
        int augen = Integer.parseInt(w[1]);
        int[] dices = new int[wuerfel];
        int gesamt = 0;

        if(wuerfel > 25 || augen > 100000){
            throw new Exception("zu groß du bob");
        }

        buffer.append(wuerfel).append("W").append(augen).append(":");

        for(int i = 0; i < wuerfel; i++){
            dices[i] = IntegerUtil.rand(1, augen);
            buffer.append(" ").append(dices[i]);
            gesamt += dices[i];
            if((i + 1) < wuerfel){
                buffer.append(",");
            }
        }

        buffer.append(" = ");
        buffer.append(gesamt);

        return buffer.toString();
    }
}