/**
* @author lautturi.com
* Java example: rand string in java, creating a random string
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
String randStr = "";
int strLen = 10;
String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#";
Random rnd = new Random();
for (int i = 0; i < strLen; i++) {
// Add a random char from the chars string to the rand string
randStr += chars.charAt(rnd.nextInt(chars.length()));
}
System.out.println(randStr);
}
}
output example:
e@jLdETopP