Newer
Older
CactusServer / src / main / java / cactusServer / utils / RandomStringGenerator.java
y-ota on 24 May 2018 735 bytes 癒されたい
package cactusServer.utils;

import java.util.Set;

import org.apache.commons.lang3.RandomStringUtils;

public class RandomStringGenerator {
	public static final String ALPHA_NUMERIC = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

	private RandomStringGenerator() {

	}

	static public String generateRandomString(int num, String seed) {
		return RandomStringUtils.random(num, seed);
	}

	static public boolean checkString(String str, Set<String> set) {
		return set.contains(str);
	}

	static public String createUniqueString(int num, String seed, Set<String> set) {
		String str;
		do {
			str = generateRandomString(num, seed);
		} while (checkString(str, set));
		return str;
	}
}