I was trying to fill a file with about ten million random characters (a-z,A-Z,' '). To my surprise the code is extremely slow. I inserted this print i to observe the progress. It was so slow that I just left the program running and went out. After about more than three hours it is still at five millions.
How can I make it fast? Most likely I am doing something wrong. Shouldn't this task be done in less than a couple of minutes?
My system is probably quite powerful one: Dell Precision with Xeone processor having twelve logical cores and 48GBs of RAM.
public class RandChars{
public RandChars(){
}
public static void main(String[] args) throws FileNotFoundException {
final String alphabet = "AaBbCcDdEeFfGgHhIiJjKkLlMmNnO oPpQqRrSsTtUuVvWwXxYyZz";
final int N = alphabet.length();
final int NumChars=10240000;
String SearchString=null;
PrintWriter text_writer = new PrintWriter("SearchString.txt");
Random r = new Random();
for (int i = 0; i < NumChars; i++) {
SearchString += alphabet.charAt(r.nextInt(N));
System.out.println(i); // I know this is making it a bit slow
}
text_writer.println(SearchString);
text_writer.close();
}
}
UUID.randomUUID().toString();and concat it sevreal times.. \$\endgroup\$functionName.contains("random") == truelol \$\endgroup\$