[INDENT]package com.xvolks.dofus2.toolkit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RandomToolkit {
public static String getRandomFlashKey() {
String key = "";
int size = 20;
int cpt = 0;
while (cpt < size) {
key = key + getRandomChar();
cpt = cpt + 1;
}
return key + checksum(key);
}// end function
private static String checksum(String toCheck) {
String[] hex_chars = new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };
int checkSumIndex = 0;
int cpt = 0;
while (cpt < toCheck.length()) {
checkSumIndex = checkSumIndex + toCheck.charAt(cpt) % 16;
cpt = cpt + 1;
}
return hex_chars[checkSumIndex % 16];
}// end function
private static String getRandomChar() {
double rnd = Math.ceil(Math.random() * 100);
if (rnd <= 40) {
return "" + (char) ((int) (Math.floor(Math.random() * 26) + 'A'));
}
if (rnd <= 80) {
return "" + (char) ((int) (Math.floor(Math.random() * 26) + 'a'));
}
return "" + (char) ((int) (Math.floor(Math.random() * 10) + '0'));
}// end function
public static void main(String[] args) {
Matcher m = Pattern.compile("[a-zA-Z0-9]+").matcher("");
for(int i=0; i<100000; i++) {
String s = getRandomFlashKey();
if(!m.reset(s).matches()) {
System.err.println(s+ " est fausse");
break;
} else {
System.out.println(i+ " - "+ s);
}
}
}
}