Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Random;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Algorithm {
- static HashMap<String, String> dictionarie = new HashMap<String, String>();
- static Random rand = new Random();
- public static String getFromDict(String dict, int count) {
- StringBuffer result = new StringBuffer();
- for (int i = 0; i < count; i++)
- result.append(dict.charAt(rand.nextInt(dict.length())));
- return result.toString();
- }
- public static String change(String str) {
- StringBuffer output = new StringBuffer();
- Matcher matcher = Pattern.compile("\\\\([a-z])\\{([1-9][0-9]*|[1-9][0-9]*,[1-9][0-9]*)\\}").matcher(str);
- while (matcher.find()) {
- if (dictionarie.containsKey(matcher.group(1))) {
- int quant = 0;
- if (matcher.group(2).contains(",")) {
- String[] numb = matcher.group(2).split(",");
- if (Integer.parseInt(numb[1]) > Integer.parseInt(numb[0]))
- quant = rand.nextInt(Integer.parseInt(numb[1]) - Integer.parseInt(numb[0]) + 1 ) + Integer.parseInt(numb[0]);
- else {
- matcher.appendReplacement(output, "\\"+matcher.group(0));
- continue;
- }
- } else
- quant = Integer.parseInt(matcher.group(2));
- matcher.appendReplacement(output, getFromDict(dictionarie.get(matcher.group(1)), quant));
- } else
- matcher.appendReplacement(output, "\\"+matcher.group(0));
- }
- matcher.appendTail(output);
- return output.toString();
- }
- public static void main(String[] args) {
- dictionarie.put("d", "0123456789");
- dictionarie.put("w", "abcdefghijklmnopqrstuvxwyz");
- for(int i = 0; i < 1000; i++)
- System.out.println(change("\\d{3}.\\d{3}.\\d{3}-\\d{2}"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement