creating a a random string
/**
* @author lautturi.com
* Java example: java create random string
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
String randStr = "";
// The chars that are used to generate the random string
String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#";
int size = 10;
for (int i = 0; i < size; i++) {
// Add a random char from the chars string to the rand string
randStr += chars.toCharArray()[new Random().nextInt(chars.length())];
}
// print the random string
System.out.println(randStr);
}
}
output example:
!THzS@VdC5