package org.cobbzilla.wizardtest;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;

import java.security.SecureRandom;
import java.util.List;

import static org.cobbzilla.util.daemon.ZillaRuntime.now;

public class RandomUtil {

    public static final String TEST_EMAIL_SUFFIX = "@example.com";

    private static final SecureRandom RANDOM = new SecureRandom();

    public static String randomName() { return randomName(20); }

    public static String randomName(String prefix) { return prefix + "_" + randomName(20); }

    public static String randomName(int length) { return RandomStringUtils.randomAlphanumeric(length); }

    public static String randomDigits(int length) { return RandomStringUtils.randomNumeric(length); }

    public static String randomEmail (String prefix) { return prefix + "-" + randomName(5) + now() + TEST_EMAIL_SUFFIX; }

    public static String randomEmail () { return randomName(5) + now() + TEST_EMAIL_SUFFIX; }

    public static String randomEmail (int length) {
        final String baseEmail = now() + TEST_EMAIL_SUFFIX;
        final int emailLength = Math.max(10, length - baseEmail.length());
        return randomName(emailLength) + baseEmail;
    }

    public static long randomTime(int minDaysInFuture) {
        int days = minDaysInFuture + RANDOM.nextInt();
        return now() + (days * 1000 * 60 * 60 * 24);
    }

    public static boolean randomBoolean() { return RandomUtils.nextInt(0, 2) % 2 == 0; }

    public static <T> T pickMod(T[] things, int i) {
        if (i <= 0 || i > things.length) i = things.length;
        return things[things.length % i];
    }
    public static <T> T pickMod(List<T> things, int i) {
        if (i <= 0 || i > things.size()) i = things.size();
        return things.get(things.size() % i);
    }

}

@@ -141,54 +141,80 @@
 ava.
-security.SecureRandom;%0Aimport java.util.List;%0A
+util.List;%0A%0Aimport static org.cobbzilla.util.daemon.ZillaRuntime.RANDOM;
 %0Aimp
@@ -368,76 +368,8 @@
 %22;%0A%0A
-    private static final SecureRandom RANDOM = new SecureRandom();%0A%0A
     

use zilla random